Emacs Customization Grab Bag

A bunch more I added back to my emacs configuration, plus a few new things:

(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
        (let* ((my-lisp-dir "~/.emacs.d/")
              (default-directory my-lisp-dir))
           (add-to-list 'load-path my-lisp-dir)
           (normal-top-level-add-subdirs-to-load-path)))

This adds all subdirectories of ~/.emacs.d/ to my load-path, ensuring that I don’t have to worry about manually updating my load path.

(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m)

In shell mode, there is often a problem where the control-m character is displayed. This *should* fix the problem, but I actually still have issues. When I’m in shell-mode, the following is an example of my output:

nflath@nflath-laptop:~/clojure$ ls
build.xml          clojure.jar                clojure-sources.jar  readme.txt
classes            clojure-slim-1.0.0.jar     epl-v10.html         src
clojure-1.0.0.jar  clojure-slim.jar           pom-template.xml     svninfo.txt
clojure_1.0.0.zip  clojure-sources-1.0.0.jar  pom.xml

Which is very suboptimal, to say the least. This did not occur before I wiped my configuration file, so I fixed it once before, but I couldn’t find the configuration setting I used to do so. If you have any ideas, please let me know - I use shell mode just about constantly and this is a huge problem.

(fset 'yes-or-no-p 'y-or-n-p)
(show-paren-mode 1)
(setq kill-read-only-ok t)
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(setq inhibit-startup-message t)
(when window-system (global-unset-key "\C-z"))

These are just some general Emacs customizations I use. The first line standardizes emacs; instead of sometimes asking for yes/no and sometimes y/n, it will always request y/n. show-paren-mode will highlight the parenthesis matching the one you are over, which is great when you are doing any type of coding. The next line tells emacs not to throw an error when you attempt to kill text in a read-only buffer; it will just save it to the kill ring, which is what I want in most cases.

(defun copy-line (&optional arg)
  "Do a kill-line but copy rather than kill. This function directly calls
kill-line, so see documentation of kill-line for how to use it including prefix
argument and relevant variables. This function works by temporarily making the
buffer read-only, so I suggest setting kill-read-only-ok to t."
  (interactive "P")
  (toggle-read-only 1)
  (kill-line arg)
  (toggle-read-only 0))
 
(defun copy-whole-line (&optional arg)
  (interactive)
  (save-excursion
    (move-beginning-of-line 1)
    (copy-line arg)))
 
(global-set-key (kbd "C-x y") 'copy-whole-line)

I found copy-line online somewhere a while back, but don’t use it very much. What I do use a lot is copy-whole-line, which doesn’t require me to C-a to yank an entire line of text. This is a frequent enough occurrence that I bound it to it’s own keybinding.

(setq eldoc-idle-delay 0)
(autoload 'turn-on-eldoc-mode "eldoc" nil t)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)

Eldoc is a minor mode that is invaluable for lisp programming - or even other languages, I also use c-eldoc-mode. It will display the arguments to the function you are calling in the mode line. This can be used either as you are writing code and need to remember what order arguments are in, or when just reading it and wondering what each argument corresponds to. Many times this saves having to look up the full documentation for a function. The configurations above will enable eldoc in elisp modes and set it to display the arguments immediately, instead of waiting.

2 Responses to “Emacs Customization Grab Bag”

  1. Stephane says:

    To fix your issue with [0mc, try this:

    (require ‘ansi-color)
    (add-hook ’shell-mode-hook ‘ansi-color-for-comint-mode-on)

  2. [...] talked about eldoc-mode before here. It is still one of my favourite minor modes, and I am greatly saddened whenever I realize a [...]

Leave a Reply