Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7e2f7d2892
Fetching contributors…

Cannot retrieve contributors at this time

184 lines (162 sloc) 9.711 kb

My personal Emacs configuration

Emacs is no more about text editing than astronomy is about telescopes.

[#A] make a script to deploy automatically this configuration everywhere where is possible

might just be a shell script or CMake or the new project-organizer tool which handles the whole thing

See how to use variables like special-buffer-regexps to have a better control over the buffer windows

use the ERT testing framework to test my functions

Write a function that setups all the possible paths automatically

See if it’s worthy to byte compile everything or not

  • CLOSING NOTE [2010-05-24 Lun 14:01]
    Solved nicely with byte-compile-cache, some cases it could not work

Include another more up-to-date semantic version finally

  • CLOSING NOTE [2010-08-08 Dom 16:13]
    included a version from cvs

Add options to create encrypted org-files for storing password and more delicate informations

  • CLOSING NOTE [2011-04-12 Tue 14:03]
    using gnupg already to manage it

REJECTED Build an automatic list of versions of the packages

  • CLOSING NOTE [2011-06-21 Mar 15:22]

change all the functions definitions adding a personal prefix

  • CLOSING NOTE [2011-12-10 Sat 20:03]
    all the functions have a ca- prefix now

Links

Sparse documentation

From newcomment.el:

Define a custom variable with a dynamic list

(defcustom comment-style 'indent
  "Style to be used for `comment-region'.
See `comment-styles' for a list of available styles."
  :type (if (boundp 'comment-styles)
            `(choice ,@(mapcar (lambda (s) `(const ,(car s)))
                               comment-styles))
          'symbol)
  :version "23.1"
  :group 'comment)

How to extend emacs

example about advising functions

  • If you can use the mode hooks provided by the author, use them instead.
  • If there is a bug in the original mode, just fix it in the original code and submit a patch.
  • If there is a new feature you want, add it to the original mode and submit a patch. Talk to the author, work with him, and it will most likely end up in the next release.
  • If you are an Emacs developer, working on Emacs itself, or one of the modes shipped with Emacs, never use advice. It’s the least maintainable method of extending Emacs with the exception of a pure fork, and since you’re working on Emacs itself, it’s not a fork.
  • If your patch is not accepted, or you know that what you want is fringe enough or hackish enough to not warrant submitting a patch, only then should you use advice or fork the project.

Some very useful commands

  • kill-buffer-and-window
  • shell
  • list-load-path-shadows (find hiding libraries)
  • symbol-function (find where a symbol is defined)
  • trace-function (for debugging and see what really happens), untrace-function to undo
  • read-string (getting a string from the minibuffer, see how prompt strings work)
  • completing-read (creating a nice menu getting the tab-completion in minibuffer)
  • string-rectangle (select a rectangle and replace the inserted text \C-x r t)
  • split-line (split a line keeping indentation, bound to \C-\M-o)
  • c-set-style, set the indentation style for your code, many preset useful settings Used for java and cc-mode
  • thing-at-point, gets what it can find at local point
  • regexp-builder very nice to create dynamically a regexp
  • align align list of things in a more readable way
  • ielm, nice interactive elisp environment
  • semantic-mrub-switch-tags, allows to jump to last modified positions with semantic
  • C-c C-h (or some other prefix) allows you to see all the commands you can give
  • describe-mode (C-h m)

Tips and tricks

Using always spaces instead of tabs

There are many opinions about the usage of tabs or spaces in source code. I think the best and easiest approach is to use spaces everywhere, tabbing will still create the right number of spaces.

Setting up the right style with c-set-style we can have the desired behavior. This is the to set:

;; Setting indent-tabs-mode for only spaces
(setq indent-tabs-mode nil)

If you want to convert from spaces to tabs or tabs to spaces use tabify or untabify respectively.

Make emacs ignore a key

See for example

(global-set-key (kbd "<f2>") 'ignore)

Untabify before writing out a file

In this example we use a hook to untabify before it’s finally written out

(defun ca-java-mode-untabify ()
  "untabify the whole buffer"
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "[ \t]+$" nil t)
      (delete-region (match-beginning 0) (match-end 0)))
    (goto-char (point-min))
    (if (search-forward "\t" nil t)
        (untabify (1- (point)) (point-max))))
  nil)

;; example on how to use this function
;; (add-hook 'java-mode-hook
;;           '(lambda ()
;;              (make-local-variable 'write-contents-hooks)
;;              (add-hook 'write-contents-hooks 'ca-java-mode-untabify)))

Replacement stuff in emacs

List of things to substitute with emacs

Key Value contained
\& the original found text
\1, \2, etc. the 1st, 2nd, etc. parenthesized subgroup in the found text
\# the number of replacements done so far
\? a string obtained by prompting the user on each match
\,(lisp-expression …) the result of evaluating an arbitrary function

How to set up your initialization

The configuration should be as modular as possible, and should use autoloads when possible. There are different way to set up variables on not loaded libraries:

  • simple variables use simply setq and evaluate it on emacs loading
  • adding default values of an extension for example (define-key foo-mode-map …) use eval-after-load. This will add default values once the extension is loaded.
  • run code after initialization Use mode hooks, normally simply <mode-name>-hook, and modify them with add-hook

Very nice explanation about emacs and replacing functions

Org mode

  • org mode as a gtd system Create some subsections
    • tasks
    • calendar
    • projects
    • financial (use ledger for that)
    • borrowed
    • configuration?
Jump to Line
Something went wrong with that request. Please try again.