parsed.org

Tips by tag: elisp

Add Newline When Saving Files by cygnus on Feb 16, 2005 02:30 PM

Emacs can be configured to add a trailing newline by updating ~/.emacs as follows:

(setq require-final-newline t)
dot-emacseditorselispemacsnewline
Changing Face Colors by cygnus on Mar 06, 2005 07:48 PM

To change the color of a particular face (e.g. font-lock-comment-face), use this elisp (editing where necessary):

(custom-set-faces
 '(font-lock-comment-face
   ((t (:foreground "lightblue" (background light))))
   )
)

lightblue and other color names are defined in rgb.txt, included with your emacs and X installations.

colorsconfigurationeditorselispemacsx11
Customization of global shortcut keys by cygnus on Jan 12, 2005 10:30 AM

To set your own global keybinding to a function, use global-set-key in your ~/.emacs as follows:

(global-set-key "C-cl" 'enlarge-window-horizontally)
configurationdot-emacseditorselispemacskeystrokes
Goto-line by cygnus on Jan 12, 2005 10:31 AM

Use this in your ~/.emacs to bind a key to goto-line:

(global-set-key "C-cl" 'goto-line)
configurationdot-emacseditorselispemacskeystrokes
Mouse avoidance mode by cygnus on May 03, 2006 02:59 PM

Emacs features a minor mode, mouse-avoidance-mode, which causes the mouse to move away from the Emacs point when the point gets too close. This can be really helpful if you're used to moving your mouse away from the cursor to avoid typing "underneath" the mouse. In your custom-set-variables section in ~/.emacs, add the appropriate elisp:

(custom-set-variables
 .
 .
 '(mouse-avoidance-mode (quote animate) nil (avoid))
 .
 .

The animation parameters of mouse-avoidance-mode can be customized with M-x customize.

configurationeditorselispemacsmouseneat
Pasting With the Mouse by cygnus on Feb 09, 2006 04:12 PM

If you use middle-clicking to paste into Emacs windows but don't like how the paste occurs at the click location and would rather paste at point, use this in your ~/.emacs:

(setq mouse-yank-at-point t)

Thanks to Kevin Turner for pointing this out.

configurationdot-emacseditorselispemacsmousepointyank
Setting Modes by xinu on Jan 15, 2005 02:52 PM

If you wish for a particular file to be handled with a mode that isn't already associated with its extension, you may put a header like this anywhere in the file:

-*- mode: outline; mode: auto-fill -*-

Alternatively, you can update your ~/.emacs to use modes based on file extension or filename. For example, to use html-mode for files ending in .tpl:

(setq auto-mode-alist
  (cons '("\\.tpl$" . html-mode) auto-mode-alist))

You can also configure Emacs to use a specific major and minor mode together for a given file extension. This example defines my-mode to load outline-mode (a major mode) and auto-fill-mode (a minor mode) for files ending in .foo:

(defun my-mode ()
  (outline-mode)
  (auto-fill-mode))

(setq auto-mode-alist
  (append '(("\\.foo$" . my-mode))
    auto-mode-alist))
configurationdot-emacseditorselispemacs

Use this elisp snippet (in your ~/.emacs) to instruct your Emacs python-mode to use the proper python executable on a system with multiple pythons installed:

(setq py-python-command "/usr/bin/python2.3")
dotemacselispemacsinterpreterinvocationlanguagesprogrammingpython
RSS