Emacs HowTo's - <troll>is WAY better than Vi</troll>


How to jump to a function definition ?

With xref and tags (sources : 1, 2) :

  1. preliminary : from the shell, scan your code to build / update a database of references : ./TAGS
    etags *
  2. within Emacs :
    1. M-. (xref-find-definitions) : look for identifier at point
    2. M-, (xref-pop-marker-stack) : return to starting location

Other methods :


How to setup Jabber / XMPP to use Emacs as a GTalk client ?

Setup :

  1. Get the Jabber extension :
    • For Debian, it's packaged as emacs-jabber (get a hint for the load-path with : dpkg -L emacs-jabber)
    • for Windows (download and extract into the extensions directory, declared as load-path in Emacs configuration file). Important notes below.
  2. In the configuration file, let Emacs know where it may find the extension, then "require" it :
    (add-to-list 'load-path "/path/to/the/jabber/extension")
    (require 'jabber)
    My advice :
    • There may be several load-path directives in the configuration file (but possibly a better way to configure this ?)
    • The path must lead to the directory containing the extension files. It won't work if it's the path to a generic directory containing all extensions as sub-directories
    • If running on Windows, don't forget to change the \ into / in the path
  3. start Emacs
  4. ALT-x jabber-customize
  5. Edit the Jabber Account List section (put the cursor on Show Value, then ) :
    • JID (Jabber ID) : john.smith@gmail.com
    • Password : 12345
    • Network server : talk.google.com
    • Connection type : Legacy SSL/TLS
    Don't forget to save with Save for future sessions.
  6. add into the configuration file :
    ; JABBER / XMPP (GTalk)
    (require 'jabber)
    (setq-default jabber-account-list (quote (
    		(:password . "12345")
    		(:network-server . "talk.google.com")
    		(:connection-type . ssl)
  7. You're ready to connect !

On Windows + behind a corporate firewall/proxy :

Well, things get tough (details) ! Here is what ALMOST worked :

  1. Apply this configuration :
    ; JABBER / XMPP (GTalk)
    (require 'jabber)
    (setq-default jabber-account-list (quote (
    		(:password . "12345")
    		(:network-server . "")
    		(:port . 12345)
    		(:connection-type . ssl)
  2. Setup a tunnel with PuTTY from to talk.google.com:443
  3. This fails saying :
    Opening TLS connection to `'...
    Opening TLS connection with `gnutls-cli -p 12345'...failed
    Opening TLS connection with `gnutls-cli -p 12345 --protocols ssl3'...failed
    Opening TLS connection with `openssl s_client -connect -no_ssl2 -ign_eof'...failed
    Opening TLS connection to `'...failed
    Jabber connection failed
    john.smith@gmail.com/nil: connection lost: `nil'

Other failure :

Connecting may also fail saying :

Opening TLS connection to `talk.google.com'...
Opening TLS connection with `gnutls-cli -p 5223 talk.google.com'...done
Opening TLS connection to `talk.google.com'...done
john.smith@gmail.com/nil: connection lost: `exited abnormally with code 1
Workaround : append to the configuration file (source) :
(setq starttls-use-gnutls t
	starttls-gnutls-program "gnutls-cli"
	starttls-extra-arguments '("--starttls" "--insecure")
But the connection is now insecure !

Usage :

  1. Connect : ALT-x jabber-connect
  2. You'll be prompted for your Jabber ID (JID) : john.smith@gmail.com
  3. Once connected, the buddy list is available in the *-jabber-roster-* Emacs buffer.
  4. To start a conversation, just place the cursor on the line of a contact name and . This will open a new Emacs buffer.
  5. Enjoy !
  6. Disconnect : ALT-x jabber-disconnect

How to insert special characters in the minibuffer ?

character to insert command

Emacs : how to collapse / expand regions ?

This is achieved with the built-in HideShow module, which is activated by the ALT-x hs-minor-mode command (When activated, (hs) should appear in the status bar).
All keyboard shortcuts start with C-c @. Those ending in s are used to show stuff. Those in h are there to hide stuff.

Depending on your language / settings, typing the @ character itself may also necessitate to hit Alt Gr-0à@, making this a pretty costly 6-keys shortcut .

object hide show
  1. place the point inside the (, {, or [ to collapse
  2. C-c @ C-h
  1. place the point inside the collapsed (, {, or [ to expand. This should appear as ....
  2. C-c @ C-s
  1. place the point 1 level higher than the level to hide
  2. C-c @ C-l
  1. place the point within the (, {, or [ to expand
  2. C-c @ C-s
all blocks C-c @ ESC C-h C-c @ ESC C-s

How to open files in an already running Emacs instance from the shell ?

  1. in Emacs : Alt-x server-start
  2. in the shell : emacsclient fileToOpenInEmacs &
  3. (do some work)
  4. when you're done, close the buffer : Ctrl-x #

How to remove duplicate lines ?

In the configuration file, add :

; Remove duplicate lines
; source : http://www.emacswiki.org/emacs/DuplicateLines#toc2

; Execute this with :
;	M-x uniquify-all-lines-buffer

(defun uniquify-all-lines-region (start end)
"Find duplicate lines in region START to END keeping first occurrence."
(interactive "*r")
	(let ((end (copy-marker end)))
				(goto-char start)
				(re-search-forward "^\\(.*\\)\n\\(\\(.*\n\\)*\\)\\1\n" end t))
			(replace-match "\\1\n\\2")))))

(defun uniquify-all-lines-buffer ()
"Delete duplicate lines in buffer and keep first occurrence."
(interactive "*")
(uniquify-all-lines-region (point-min) (point-max)))

And use it with : ALT-x uniquify-all-lines-buffer