5 elisp snippets

Change font size in emacs

To change the font size in the current buffer:

  • C-x C-+ - increase font size

  • C-x C-- - decrease font size

Follow either with +, - or 0 for continued adjustment.

To change the font size in all buffers:

(set-face-attribute 'default nil :height 120) ;; where `height` is 10x point size
Published 23 Mar 2013
Tagged emacs and elisp.


Working with R in emacs

1) Install R.

2) Install ESS:

sudo aptitude install ess=12.09-1

3) Require ess-site:

(add-to-list 'load-path "/usr/share/emacs/site-lisp/")
(require 'ess-site)

4) Load R within emacs via M-x R.

Published 26 Mar 2013
Tagged emacs, r-lang and elisp.


Default fonts with emacsclient/emacs --daemon

I've been using set-default-font in my .emacs file to configure emacs to use my favorite programming font.

(set-default-font "Droid Sans Mono Slashed-10") ;;; set default font

I use emacs --daemon to keep an instance of emacs running as a background process on my development machine so that I can run emacsclient to call up an emacs window (frame) instantaneously (and keep the same session running even after a close the emacs frame).

Suddenly (after an aptitude safe-upgrade, I think, but I'm not sure what triggered this change), emacs frames that are created by emacsclient connecting to the emacs --daemon instance no longer used my default font when initially opened. The default font worked properly for stand-alone emacs instances (opened with emacs), and for emacsclient, executing (set-default-font) after startup worked fine, but it no longer worked automatically.

To fix this, I had to set up a default-frame-alist, which I believe defines commands to execute whenever a new frame is opened.

(set-default-font "Droid Sans Mono Slashed-10") ;;; set default font
(setq default-frame-alist '((font . "Droid Sans Mono Slashed-10"))) ;;; set default font for emacs --daemon / emacsclient

By the way, I also discovered the describe-font elisp function while trying to diagnose this issue.

(describe-font "Droid Sans Mono Slashed-10")
;; or M-x describe-font <RETURN> Droid Sans Mono Slashed-10 <RETURN>

which opens a *Help* buffer containing:

name (opened by): -unknown-Droid Sans Mono Slashed-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1
       full name: Droid Sans Mono Slashed:pixelsize=13:foundry=unknown:weight=normal:slant=normal:width=normal:spacing=100:scalable=true
            size: 13
          height: 17
 baseline-offset:  0
relative-compose:  0
Published 11 May 2013
Tagged emacs and elisp.


Simple emacs mode for .gitignore files.

Through the power of generic-mode, adding the following lines to your .emacs file will add syntax-coloring support for .gitignore, .svnignore, etc. files. And by "syntax-coloring" I mean that lines that start with a # will be marked as comments.

(require 'generic-x)
(add-to-list 'auto-mode-alist '("\\..*ignore$" . hosts-generic-mode))

Actually, any text after an un-escaped # will be marked as a comment, which isn't the way Git and SVN interpret those files. (TODO: it would be pretty simple to add a dot-ignore-generic-mode that handles this correctly.)

Published 13 May 2013
Tagged emacs, elisp and todo.


Using js-mode's indent logic in js2-mode

Steve Yegge's js2-mode is a sweet major mode for working with JavaScript in Emacs, but its auto-indentation logic is notoriously frustrating.

Here's a somewhat hack-y workaround: switch to javascript-mode before calling indent-region and then switch back.

;; use js-mode's indent logic, by pressing C-M-| (C-M-S-\)
(defun rlw/js-indent-region () (interactive) (js-mode) (indent-region (region-beginning) (region-end)) (js2-mode) )
(define-key js2-mode-map (kbd "C-M-|") 'rlw/js-indent-region)

PS: I haven't yet had a chance to sort these out, but there are at least four or five JavaScript modes:

The first two are supposed to address js2-mode's indentation problems (among other enhancements).

Published 7 May 2013
Tagged emacs, elisp and javascript.


This page was generated at 9:56 PM on 15 Jan 2016.
Copyright © 1999 - 2016 Rodney Waldhoff.