# Emacs Notes

- Page: https://shared.btbytes.com/p/emacs
- Date: 2020-03-28
- Tags: lisp, emacs, text-editor

This page is a journal of my experiments with emacs. In November of 2008, I decided to use emacs for all my text editing purposes, after long been convinced of Emacs's power and utility in editing programs and texts. At this time, I consider myself to be an adequate user of [vim](http://www.vim.org/), [emacs](http://www.aquamacs.org/) and [TextMate](http://macromates.com). My goal is to teach myself emacs in an [auto-didactic](http://en.wikipedia.org/wiki/Autodidact) manner and make a note of the questions I had and the solutions I found for them. I hope this serves as a reminder for myself on a later date.

**Note:** All the instructions on this page, unless otherwise noted, are tested on Mac OS X systems and Aquamacs.

## Python + Emacs


Install `rope`, `ropemode`, `pep8` and `pyflakes`.

    $ pip install ropemode pep8 pyflakes

Install `yasnippet-bundle` and `pymacs` in emacs:

    M-x package-install yasnippet-bundle

References:

- [Emacs as a powerful Python IDE](http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/)
- [My emacs python environment](http://www.saltycrane.com/blog/2010/05/my-emacs-python-environment/)

## Emacs Client on Mac OS X

[Here](http://skife.org/emacs/mac/osx/2011/03/17/emacs-client-mac.html) is a nice AppleScript created by Brian McCallister that provides proper emacsclient behaviour. Update: this script launches a "terminal" window, which is an annoyance.

## Navigation

  Go to                      Shortcut
  -------------------------- --------------
  Goto line                  `M-gg`.
  End of the buffer          `M-x >`
  End of the line            `C-e`
  Beginning of the line      `C-a`

Editing
-------

  Do what                      Shortcut
  ---------------------------- --------------
  zap-to-char (say `e`)        `M-z e`
  merge multiple lines         `M-^` (alt-shift-6)


Customising emacs
-----------------

Customizing emacs is done through editing `~/.emacs` file. Though, if
you are using `emacs-starter-kit` you will be putting files under
`emacs.d`.

### Adding a new key binding.

You can bind any operation that you can do in emacs to a set of key strokes. For example: the emacs-git integration -- `magit` can be invoked by typing `M-x magit-status`. But, this gets tiring after a while, so you may want to assign a short cut. Short cuts in Emacs start with 'C-c'. You have to decide what comes after `C-c`. In this case, I chose magit-status.

Add the following lines to your .emacs file:

    ;; C-c ms Magit-status
    (global-set-key (kbd "C-c ms") 'magit-status)

The first line is the comment (a good practice) and the second line tells emacs to call `magit-status` when you press `C-c ms`.

### After editing a custom function in .emacs file how do I reload it?

Select the block of code that you want to reload and hit `C-x C-e` (evaluate). This can also be achieved by positioning the cursor (point in emacs lingo) after the last closing parentheses of the function and typing `C-x C-e`.

## Editing ConTEXt files with Emacs

Install ConTEXt. Install AUCTEX using `port` (on mac).

    $ sudo port install auctex

Active AucTEX by putting this `(load "auctex.el" nil t t)` in `.emacs`.

## Auto completion.

Install [YASnippet](http://code.google.com/p/yasnippet/) to get auto-completion on emacs. To use YASnippet, type in the trigger word and press TAB. For example, typing `def` and pressing TAB will give you

<pre class="python">
    def name():
        """
        """
</pre>

The next tab press allows you replace the default function name with your own, with subsequent tabs taking you to the parameter list, docstring and finally the body of the function

## What programming font?

[This page](http://www.proggyfonts.com/index.php?menu=download) has a nice collection of free programming fonts optimized for editing code over long durations of code. The rule of thumb to remember while selecting a programming font is: it should be a fixed width font. This is especially true in languages like "Python":Python where indentation is essential in understanding the code flow.

I currently use Monaco, a font that is available on Mac OS X set to size 10.

## Emacs Muse Notes

[Muse tutorial](http://web.archive.org/web/20071217174211/http://www.linux.com/feature/61208#commentthis).

Instead of editing the muse-latex.el and muse-book.el files, just use
customize on the muse-latex-header and muse-book-latex-header variables.
Upgrades to new versions of muse will be much smoother.

## Emacs + Git integration

-   [Magit cheatsheet](http://web.archive.org/web/20091123062517/http://daemianmack.com/magit-cheatsheet.html)
-   [Magit user
    manual](http://web.archive.org/web/20080906024539/http://zagadka.vm.bytemark.co.uk/magit/magit.html)

Main entry point `M-x magit-status` (bound to C-c ms). Go to the magit
buffer `*magit: PRJNAME*` and press tab on the line containing the
filenames. The modified text will expand underneath. Press `TAB` again
collapse.

Press `g` in the magit buffer to refresh git status. or execute
`M-x magit-status` from one of the repository files.

## Removing trailing white spaces

The [emacs manual](http://www.gnu.org/software/emacs/manual/html_node/emacs/Useless-Whitespace.html)
defines tells us that setting buffer variable `show-trailing-whitespace`
to `t` will show trailing white spaces.

    (setq show-trailing-whitespace 't)

Paste the above line into the current emacs buffer and evaluate the
statement by pressing `C-x C-e`. Delete the white spaces with
`M-x delete-trailing-whitespace`

## Check to see if your emacs configuration is correct.

[Source](http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/bed5b2bd8b237f5a?pli=1)

    emacs -q --eval '(condition-case err (progn (load "~/.emacs") (kill-emacs 0)) (error (kill-emacs 1)))'

## Shut down emacs gracefully from the command line

    emacsclient -n -e '(kill-emacs)'

  ------------------------------------------------------------------------
  How to ?                                                Command
  ------------------------------------------------------- ----------------
  Create a Directory from within emacs                    `M-x make-direct
                                                          ory`

  [Spell                                                  `M-x ispell`
  check](http://www.gnu.org/software/emacs/manual/html_no
  de/emacs/Spelling.html)

  Undo                                                    `C-x u` or `C-_`

  Describe key                                            `C-h k`

  Describe bindings                                       `C-h b`

  Describe functions                                      `C-h f`
  ------------------------------------------------------------------------

## Emacs Server/Client

See [Running emacs as
daemon](http://www.emacswiki.org/emacs/EmacsAsDaemon).

## Setting up SLIME

[Movie showing how to setup slime, swank, sbcl and
emacs](http://web.archive.org/web/20100621011649/http://common-lisp.net/project/movies/movies/slime.mov)

Some notes:

check out slime and put it somewhere convenient, ie.,
`$HOME/elisp/slime`.

Put the following lines in `.sbclrc`

    (require :asdf)
    (push "/Users/pradeep/elisp/slime/" asdf:*central-registry*)

Load swank in sbcl:

    $ sbcl
    (asdf:oos 'asdf:load-op :swank)
    (setf swank:*use-dedicated-output-stream* nil)
    (setf swank:*communication-style* :fd-handler)
    (swank:create-server :dont-close t)

## Installing emacs24

What's new in [emacs
24](http://web.archive.org/web/20110924005916/http://batsov.com/Emacs/2011/08/19/a-peek-at-emacs24.html)?

    git clone git://git.savannah.gnu.org/emacs.git
    cd emacs
    sudo apt-get install libxpm-dev
    sudo apt-get install libgif-dev
    sudo apt-get install libtiff-dev
    ./configure
    make
    sudo make install

My initial impression of `emacs24` is that it feels much faster compared
to the stock `emacs-snapshot` available on `ubuntu maverick`.

## Understanding Emacs

* [Emacs for Humans: Glossary](https://two-wrongs.com/emacs-for-humans-glossary.html)


## Essays on Emacs

* [bare metal (the emacs essay) \| wax banks](https://waxbanks.wordpress.com/2025/08/01/bare-metal-the-emacs-essay/)

## Interesting modes

- [Deft mode](http://jblevins.org/projects/deft/) -- similar to
    notational velocity for note taking.
- [SrSpeedbar](http://www.emacswiki.org/emacs/SrSpeedbar)
- [Skewer Mode](https://github.com/skeeto/skewer-mode) and [How to use Skewer Mode](http://emacs.stackexchange.com/questions/2376/how-to-use-skewer-mode)
- [Command log](http://www.emacswiki.org/emacs/CommandLogMode)
- [Hyperbole](https://www.reddit.com/r/emacs/comments/4y0x66/any_thoughts_about_gnu_hyperbole_for_emacs/d6lotbj)

## Help

- [Using the in built help  system](http://www.emacswiki.org/emacs/EmacsChannelFaq#toc2).
- Use `C-h i d m TOPIC RET` to pull up info page on TOPIC. eg: `C-h i d m AUCTeX RET` for [AUCTeX](http://www.gnu.org/software/auctex/index.html)
- [Emacs Mini Manual (PART 1) - THE BASICS](http://tuhdo.github.io/emacs-tutor.html)
- Learning GNU Emacs, Third Edition
- [GNU Emacs manual](http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html). Free online reference.
- [GNU Emacs LISP reference](http://www.gnu.org/software/emacs/manual/html_node/elisp/index.html).  Free online reference.
- [Learn emacs lisp](http://www.emacs-doctor.com/learn-emacs-lisp-in-15-minutes.html) in 15 minutes.


## Interesting reads

- [Use GNU Emacs](https://www2.lib.uchicago.edu/keith/emacs/); [PDF](https://www2.lib.uchicago.edu/keith/emacs/emacs-tutorial.pdf) by [Keith Waclena](https://www2.lib.uchicago.edu/keith/)
- [The emacs' "lack of resources"  complaint](http://news.ycombinator.com/item?id=2255286)
- [A collection of elisp discussions on stackoverflow](http://news.ycombinator.com/item?id=2057688)
- A nice blog of elisp snippets is <http://whattheemacsd.com/>
- [Emacs Redux](http://emacsredux.com/)
- [A CEO's Guide to Emacs | Fugue](http://web.archive.org/web/20151205031354/https://blog.fugue.co/2015-11-11-guide-to-emacs.html)
- [More batteries included with emacs | Karthinks](https://karthinks.com/software/more-batteries-included-with-emacs/)

## Dotemacs

- <https://github.com/rmm5t/dotfiles>
- Magnars' [emacs.d](https://github.com/magnars/.emacs.d) has nice
  seperation of various aspects. A sep. directory for custom funcs. A
  flat organisation of files etc.,
- [Dennis' Emacs configuration file](http://web.archive.org/web/20250819204401/https://web.ics.purdue.edu/~dogbe/static/emacs_config_file.html) written in org-babel style. Informative.
- [nordlow/elis](http://web.archive.org/web/20180611014037/https://github.com/nordlow/elisp) -- lot of D related emacs stuff.
- [buildfunthings / emacs-config · GitLab](https://gitlab.com/buildfunthings/emacs-config) [via](https://www.youtube.com/watch?v=efPPh2jUrkg) youtube videon CIDER + emacs setup.


## Distributions

* spacemacs
* castlemacs
* [Centaur Emacs](https://seagle0128.github.io/.emacs.d/)
* [Elegant Emacs](https://github.com/rougier/elegant-emacs)

## Packages

- [Ivy User Manual](http://oremacs.com/swiper/)
- [howardabrams/demo-it: An Emacs package for running demonstrations and presentations from within Emacs.](https://github.com/howardabrams/demo-it)
- [emacs-reveal](https://gitlab.com/oer/emacs-reveal) -- Generates reveal.js presentations with audio explanations as [OER](https://en.wikipedia.org/wiki/Open_educational_resources) from simple texts in Org Mode with GNU Emacs. Also see [emacs-reveal-howto](https://gitlab.com/oer/emacs-reveal-howto).
- [lewang/command-log-mode: log commands to buffer](https://github.com/lewang/command-log-mode)

## Information well / emacs people

- [Youtube tutorial series -- Emacs ABC](https://www.youtube.com/playlist?list=PLrJ2YN5y27KLhd3yNs2dR8_inqtEiEweE) by Elvind Fonn.
- [Using Emacs Series | C'est la Z](http://web.archive.org/web/20160531163931/http://cestlaz.github.io/stories/emacs) [2017]
- [Full list of Tips, Tutorials and Articles - Mastering Emacs](https://www.masteringemacs.org/all-articles)
- [Endless parantheses blog](http://endlessparentheses.com/archive.html).
- [Fabrice Niessen's github](https://github.com/fniessen) -- Org themes, orgmk, emacs-leuven-theme refcards etc.,
- [Sacha Chua](http://sachachua.com/) and her [Emacs configuration file](https://dl.dropboxusercontent.com/u/3968124/sacha-emacs.html) annotated in org-mode; [source file](https://dl.dropboxusercontent.com/u/3968124/sacha-emacs.org).
- [EmacsCast | EmacsCast](https://emacscast.org/)

## TODO

**Is it possible to show the keybindings in the modeline?**

Use case: I have configured 'Fn' keys for mode specific actions, but do not remember them, or I want emacs to prompt me to use them.

Starting point: <http://www.emacswiki.org/emacs/ModeLineConfiguration>



## Random tips

- Use `M-x new-frame` create a new Emacs window associated with the current Emacs instance. Great for organising, or when running Emacs on a multi monitor setup!


## CIDER

- [CIDER RefCard](https://github.com/clojure-emacs/cider/blob/master/doc/cider-refcard.pdf)

## Journal

- 2016/6/7 -- installed emacs using this: [Getting started with emacs
  for scala programming |
  immutables](http://immutables.pl/2016/05/26/getting-started-with-emacs-for-scala-programming/)
- 2017/11/13 -- rediscovered the use of [ec][ec] script to launch
  emacsclient from the console. This is a much quicker way to launch
  into editing text than hunting on the desktop to make a quick note.
  TODO: launch the emacs window in full screen mode. increase the
  default font size. The typing feels laggy. Need to fix that.
  Position the `nb` script to open the `log/YEAR.md` file with the
  cursor at the last line of the file.
- 2017/11/14 -- have to integrate this "multi deft" elisp into my
  workflow -
  <https://gist.github.com/btbytes/bdf69ee3b478d142a324237eb4282946>
- 2018/03/14 -- [gemacs](https://github.com/glycerine/gemacs) a
  `godit` fork with more features.
- 2019/12/05 -- [Object oriented spreadsheets with example applications - David O'Toole - EmacsConf 2019](https://media.emacsconf.org/2019/18.html)

[ec]: https://github.com/mjwall/dotfiles/blob/master/bin/ec


Fri, January 3, 2020
:    Trying out Swaroop's [Rangoli-emacs](https://github.com/btbytes/rangoli-emacs)

Sat, Jan 4, 2020
:    if you see `emacs ssl certificate problem` error when installing a new dependency (`zencoding-mode` in my case), try to launch emacs from the terminal `emacs -nw` instead of the graphical mode. This finds the root certificates.

Thu, Jan 16, 2020
:   [settings up mac os x and iterm2 for emacs](http://azaleasays.com/2013/07/05/setting-up-mac-os-x-and-iterm2-for-emacs/).
    what I want is to be able to:

    1. on the laptop: use the `command` key as `option` and vice versa, so that it is similar to the "regular keyboard" (I use the Das Keyboards at work and home)
    2. in ther iterm2 window, be able to use left-alt key as `meta`. so that when I type `left-alt-m` I get `Meta-m`.
