My .emacs

I learnt Emacs back in 1983. I must have been 6 or 7 years old. My fingers got bent early on, I am a mess at handwriting. I could well be a piano player, as my fingers instintively chord.
Emacs rules and we all know it. It is the best operating system ever.
But given a good .emacs (Emacs configuration) file, it rules even more. It can even become a great editor — Even a full-fledged IDE, if that's your fancy.
Is my .emacs a good .emacs? Maybe, maybe not... Up to you to judge. This is applied plagiarism - I am not and will probably never be lisp-proficient. But I have taken snippets from all over.

[update] This section had been left untouched for long. Too long. Many years. During those many years, the ≈240 lines that made my .emacs grew too ≈400. But, yes, I am still a very happy and satisfied Emacs user. Today I can even say (and it makes me feel quite old!) that I have been an Emacs user for... 30 years!

Anyway — Prompted by one of my students, I am updating this snippet to the current (August 2013) version. Of course, it carries a sizeable amount of cruft, and has some bits that are harder to read... It even mixes some LaTeX (which I also started working with 30 years ago), as a template for some Org-mode export targets. But it works for me™ and, hopefully, it's still understandable:

  1. ;; Entra en modo de coloreado por sintaxis
  2. (global-font-lock-mode t)
  3.  
  4. ;; Si estoy en X, activa highlight-current-line (en emacs-goodies-el)
  5. (cond (window-system
  6. (require 'highlight-current-line)
  7. (highlight-current-line-on t)
  8. (highlight-current-line-set-bg-color "#003900")
  9. ))
  10.  
  11. ;; Muestra pares de paréntesis/corchetes/llaves
  12. (require 'paren)
  13. (show-paren-mode)
  14. (setq show-paren-mismatch t)
  15.  
  16. ;; Carga los modos para Haml
  17. (require 'haml-mode)
  18. (add-to-list 'auto-mode-alist '("\\.haml" . haml-mode))
  19.  
  20. ;; Si el nombre de dos archivos es igual, agrega el directorio para que el
  21. ;; nombre del buffer sea único
  22. (require 'uniquify)
  23. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  24.  
  25. ;; No me gustan los archivos de respaldo~ o con número VCS~1.0~ -
  26. ;; Guardo los respaldos automáticos en ~/.saves/
  27. (setq make-backup-files nil)
  28. (setq version-control 'never)
  29. (setq backup-by-copying t
  30. backup-directory-alist '(("." . "~/.saves"))
  31. delete-old-versions t
  32. kept-new-versions 6
  33. kept-old-versions 2
  34. version-control t)
  35.  
  36. ;; ;; Cargamos los modos de Git
  37. ;; (setq load-path (cons (expand-file-name "/usr/share/doc/git-core/contrib/emacs") load-path))
  38. ;; (require 'vc-git)
  39. ;; (when (featurep 'vc-git) (add-to-list 'vc-handled-backends 'git))
  40. ;; (require 'git)
  41. ;; (autoload 'git-blame-mode "git-blame"
  42. ;; "Minor mode for incremental blame for Git." t)
  43.  
  44. ;; La navegación en archivos más inteligente
  45. (require 'ido)
  46. (ido-mode t)
  47. (setq ido-enable-flex-matching t)
  48. ;; Cambio de buffer más eficiente, tipo IDO
  49. (setq iswitchb-mode t)
  50.  
  51. ;; Muestro explícitamente las líneas con espacios colgantes
  52. (setq show-trailing-whitespace t)
  53. ;; PgUp/PgDown no mueven la posición del cursor en la pantalla
  54. (setq scroll-preserve-screen-position 1)
  55. ;; Para que el puntero del mouse no nos estorbe
  56. (mouse-avoidance-mode 'cat-and-mouse)
  57. ;; Mostrar número actual de línea y columna
  58. (setq line-number-mode t)
  59. (setq column-number-mode t)
  60. ;; Mostrar los bloques marcados mientras los estamos marcando
  61. (setq transient-mark-mode t)
  62. ;; La campana se ve, no se oye
  63. (setq visible-bell t)
  64. ;; No seguir agregando líneas en blanco al final
  65. (setq next-line-add-newlines nil)
  66. ;; Hacer scroll línea por línea
  67. (setq scroll-step 1)
  68. ;; Si tenemos un display separado verticalmente, también doblar líneas largas
  69. (setq truncate-partial-width-windows nil)
  70. ;; Agregar automáticamente fin de línea a los archivos
  71. (setq require-final-newline t)
  72. ;; El modo default para archivos nuevos es text-mode
  73. (setq default-major-mode 'text-mode)
  74. ;; Los archivos .tmpl, .rhtml y .html.erb son templates de HTML
  75. (setq auto-mode-alist (cons '("tmpl$" . html-mode) auto-mode-alist))
  76. (setq auto-mode-alist (cons '("rhtml$" . html-mode) auto-mode-alist))
  77. (setq auto-mode-alist (cons '("html.erb$" . html-mode) auto-mode-alist))
  78. ;; Los archivos .t son tests de Perl
  79. (setq auto-mode-alist (cons '("\\\.t$" . perl-mode) auto-mode-alist))
  80. ;; Los archivos llamados /tmp/mutt* son abiertos en mail-mode
  81. (setq auto-mode-alist (cons '("^/tmp/mutt" . mail-mode) auto-mode-alist))
  82. ;; .emacs es abierto en lisp-mode
  83. (setq auto-mode-alist (cons '(".emacs$" . lisp-mode) auto-mode-alist))
  84. ;; Cuando hacemos un diff, que sea en modo unified
  85. (setq diff-switches '-u)
  86. ;; No me gusta perder un par de líneas gracias al toolbar..
  87. (setq tool-bar-mode nil)
  88. ;; Muestra como título de la ventana/icono el nombre del archivo abierto
  89. ;; (%f - filename, más largo. %b - buffer, más corto)
  90. (setq frame-title-format "Emacs - %f")
  91. (setq icon-title-format "Emacs - %b")
  92. ;; Seguimos ligas simbólicas aún si apuntan a un archivo controlado por CVS
  93. (setq vc-follow-symlinks t)
  94. ;; Recordamos nuestra posición en el buffer
  95. (setq save-place t)
  96. ;; Evitamos el splash screen al cargar, no sirve de nada...
  97. (setq inhibit-startup-message t)
  98. ;; El scratch buffer queda vacío
  99. (setq initial-scratch-message nil)
  100. ;; Configuración para Git
  101. (setq git-commiter-name "Gunnar Wolf")
  102. (setq git-commiter-mail "gwolf@gwolf.org")
  103.  
  104. ;; Evitamos actuar como estúpidos al recibir Unicode en la consola, y
  105. ;; usamos UTF para todo (para otras cosas, lo indicamos explícitamente
  106. ;; con C-x ret r
  107. (set-terminal-coding-system 'utf-8)
  108. (set-keyboard-coding-system 'utf-8)
  109. (set-selection-coding-system 'utf-8)
  110. (prefer-coding-system 'utf-8)
  111. (modify-coding-system-alist 'file "*" 'utf-8)
  112.  
  113. ;; Los buffers en text-mode y mail-mode tienen activado auto-fill; en
  114. ;; el modo de correo matamos el citado de firmas; brincamos al inicio
  115. ;; del texto.
  116. (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
  117. (add-hook 'mail-mode-hook '(lambda ()
  118. (auto-fill-mode 1)
  119. (mail-text)
  120. (flush-lines "^\\(> \n\\)*> -- \n\\(\n?> .*\\)*")
  121. ))
  122.  
  123. ;; Si tenemos mouse con ruedita de scroll, habilítala
  124. (cond (window-system
  125. (mwheel-install)
  126. ))
  127.  
  128. ;; Si estoy desde consola, no quiero barra de menú
  129. (if (not window-system) (menu-bar-mode -1))
  130.  
  131. ;; Para poder teclear caracteres acentuados al usar en consola
  132. (set-input-mode nil nil 1)
  133.  
  134. ;; Acepta 'y' o 'n' cuando pide 'yes' o 'no'
  135. (fset 'yes-or-no-p 'y-or-n-p)
  136.  
  137. ;; Combinaciones útiles de teclas
  138. (global-set-key "\C-x\." 'kill-this-buffer)
  139. (global-set-key [(C-tab)] 'bury-buffer)
  140. (global-set-key "\C-cg" 'goto-line)
  141.  
  142. ;; Ctrl-Z es una joda - Se va
  143. (global-unset-key "\C-z")
  144.  
  145.  
  146. ;;;;; La siguiente sección (mmm) fue tomada de:
  147. ;;;;; <a href="http://www2.ecos.de/~mailarc/embperl/2004-03/msg00078.html</p>
  148. <p>;;" title="http://www2.ecos.de/~mailarc/embperl/2004-03/msg00078.html</p>
  149. <p>;;">http://www2.ecos.de/~mailarc/embperl/2004-03/msg00078.html</p>
  150. <p>;;</a> needed for all mmm usage
  151. (require 'mmm-vars)
  152.  
  153. ;; needed for mmm automatic mode
  154. (require 'mmm-auto)
  155.  
  156. ;; needed for Embperl
  157. (require 'mmm-sample)
  158.  
  159. ;; now we setup mmm to automatically appear - if it is called for
  160. (setq mmm-global-mode 'maybe)
  161.  
  162. ;; ;; I don't like background colors in my perl sections, so '0' turns
  163. ;; ;; off all background fiddling. Up to you. See 'info mmm'.
  164. ;; (setq mmm-submode-decoration-level 0)
  165. (setq mmm-submode-decoration-level 2)
  166.  
  167. ;; mmm sets perl sections to use cperl-mode by default. I perfer
  168. ;; plain perl-mode, so I include the following. Up to you.
  169. (mmm-add-to-major-mode-preferences 'perl 'perl-mode t)
  170.  
  171. ;; Here force any oddball extensions used by Embperl to html
  172. ;; I use ".epl".
  173. (setq auto-mode-alist
  174. (append
  175. ;; File name ends in '.epl'.
  176. '(
  177. ("\\.epl\\'" . html-mode))
  178. auto-mode-alist))
  179.  
  180.  
  181. ;; If you want automatic Embperl mmm mode for certain files
  182. ;; (you can select with a regex on name/extension or directory -
  183. ;; see 'info mmm'), include lines similar to the following:
  184.  
  185. (mmm-add-mode-ext-class nil "\\.epl\\'" 'embperl)
  186. (mmm-add-mode-ext-class nil "\\.html\\'" 'embperl)
  187.  
  188. ;; if you use the above lines, no 'mode' line is required in the
  189. ;; source file.
  190.  
  191. (set-face-background 'mmm-special-submode-face "#000099")
  192. (set-face-background 'mmm-output-submode-face "#000079")
  193. (set-face-background 'mmm-comment-submode-face "#000059")
  194. (set-face-background 'mmm-code-submode-face "#000039")
  195. (set-face-background 'mmm-init-submode-face "#000019")
  196. ;;(set-face-foreground 'mmm-output-submode-face "Black")
  197. ;;(set-face-foreground 'mmm-code-submode-face "Black")
  198. ;;(set-face-foreground 'mmm-comment-submode-face "Red")
  199.  
  200. ;;; Modo MMM para RHTML (Ruby on Rails)
  201. ;;; Tomado de <a href="http://blog.cosinux.org/2006/06/13/emacs-and-ruby-on-rails<br />
  202. ;;;" title="http://blog.cosinux.org/2006/06/13/emacs-and-ruby-on-rails<br />
  203. ;;;">http://blog.cosinux.org/2006/06/13/emacs-and-ruby-on-rails<br />
  204. ;;;</a> (y recortado - MMM fue activado más arriba)
  205. (mmm-add-classes
  206. '((erb-code
  207. :submode ruby-mode
  208. :match-face (("<%#" . mmm-comment-submode-face)
  209. ("<%=" . mmm-output-submode-face)
  210. ("<%" . mmm-code-submode-face))
  211. :front "<%[#=]?"
  212. :back "%>"
  213. :insert ((?% erb-code nil @ "<%" @ " " _ " " @ "%>" @)
  214. (?# erb-comment nil @ "<%#" @ " " _ " " @ "%>" @)
  215. (?= erb-expression nil @ "<%=" @ " " _ " " @ "%>" @))
  216. )))
  217. (add-hook 'html-mode-hook
  218. (lambda ()
  219. (setq mmm-classes '(erb-code))
  220. (mmm-mode-on)))
  221. (add-to-list 'auto-mode-alist '("\\.rhtml$" . html-mode))
  222.  
  223. ;;;
  224. ;; Ruby-related stuff
  225. (defun try-complete-abbrev (old)
  226. (if (expand-abbrev) t nil))
  227. (add-to-list 'auto-mode-alist '("\\.rxml$" . ruby-mode))
  228. (add-to-list 'auto-mode-alist '("Rakefile" . ruby-mode))
  229.  
  230. ;;;
  231. ;; Conventions for Drupal
  232. (add-to-list 'auto-mode-alist '("\\.module$" . php-mode))
  233. (add-to-list 'auto-mode-alist '("\\.install$" . php-mode))
  234.  
  235. (setq hippie-expand-try-functions-list
  236. '(try-complete-abbrev
  237. try-complete-file-name
  238. try-expand-dabbrev))
  239.  
  240. (custom-set-faces
  241. ;; custom-set-faces was added by Custom.
  242. ;; If you edit it by hand, you could mess it up, so be careful.
  243. ;; Your init file should contain only one such instance.
  244. ;; If there is more than one, they won't work right.
  245. '(mmm-cleanup-submode-face ((t (:background "#000000"))))
  246. '(mmm-code-submode-face ((t (:background "#000039"))))
  247. '(mmm-comment-submode-face ((t (:background "#590000"))))
  248. '(mmm-declaration-submode-face ((t (:background "#0000A9"))))
  249. '(mmm-default-submode-face ((t (:background "#000079"))))
  250. '(mmm-init-submode-face ((t (:background "#000019"))))
  251. '(mmm-output-submode-face ((t (:background "#000079")))))
  252.  
  253. ;; convert dos (^M) end of line to unix end of line (and viceversa)
  254. (defun dos2unix()
  255. (interactive)
  256. (goto-char(point-min))
  257. (while (search-forward "\r" nil t)
  258. (replace-match "")
  259. )
  260. )
  261.  
  262. (defun unix2dos()
  263. (interactive)
  264. (goto-char(point-min))
  265. (while (search-forward "\n" nil t)
  266. (replace-match "\r\n")
  267. )
  268. )
  269. (custom-set-variables
  270. ;; custom-set-variables was added by Custom.
  271. ;; If you edit it by hand, you could mess it up, so be careful.
  272. ;; Your init file should contain only one such instance.
  273. ;; If there is more than one, they won't work right.
  274. '(auto-compression-mode t nil (jka-compr))
  275. '(auto-mode-alist (cons (quote ("^/tmp/mutt" . mail-mode)) auto-mode-alist) t)
  276. '(case-fold-search t)
  277. '(column-number-mode t)
  278. '(current-language-environment "UTF-8")
  279. '(default-input-method "rfc1345")
  280. '(default-major-mode (quote text-mode) t)
  281. '(ido-mode t nil (ido))
  282. '(inhibit-startup-screen t)
  283. '(org-export-latex-hyperref-options-format "\\hypersetup{
  284. urlcolor=blue,
  285. pdfkeywords={%s},
  286. pdfsubject={%s},
  287. pdfcreator={Emacs Org-mode version %s}}
  288. ")
  289. '(org-file-apps (quote ((auto-mode . emacs)
  290. ("\\.mm\\'" . default)
  291. ("\\.x?html?\\'" . default)
  292. ("\\.pdf\\'" . "evince -p %1 %s"))))
  293. '(save-place t nil (saveplace))
  294. '(save-place-limit 30)
  295. '(setq ido-enable-flex-matching t)
  296. '(show-paren-mode t)
  297. '(show-trailing-whitespace t)
  298. '(tool-bar-mode nil)
  299. '(transient-mark-mode t)
  300. '(uniquify-buffer-name-style (quote post-forward-angle-brackets) nil (uniquify))
  301. '(vc-follow-symlinks t)
  302. '(version-control (quote never))
  303. '(visible-bell t))
  304.  
  305. ;; Para que org-mode genere los archivos de fuentes en Graphviz,
  306. ;; Gnuplot o Ditaa. Receta copiada de:
  307. ;;
  308. ;; http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-dot.html
  309. (org-babel-do-load-languages 'org-babel-load-languages
  310. '((dot . t)) )
  311.  
  312. (org-babel-do-load-languages 'org-babel-load-languages
  313. '((ditaa . t)))
  314.  
  315. (org-babel-do-load-languages 'org-babel-load-languages
  316. '((gnuplot . t)))
  317.  
  318.  
  319. (defun my-org-confirm-babel-evaluate (lang body)
  320. ; don't ask when the block is ditaa, dot or gnuplot
  321. (not (or (string= lang "dot")
  322. (string= lang "gnuplot")
  323. (string= lang "ditaa"))))
  324. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  325.  
  326.  
  327. ;; Exportación de org-mode a Beamer - Copiado de
  328. ;; <a href="http://emacs-fu.blogspot.com/2009/10/writing-presentations-with-org-mode-and.html<br />
  329. ;;<br />
  330. ;;" title="http://emacs-fu.blogspot.com/2009/10/writing-presentations-with-org-mode-and.html<br />
  331. ;;<br />
  332. ;;">http://emacs-fu.blogspot.com/2009/10/writing-presentations-with-org-mode...</a> allow for export=>beamer by placing
  333. ;; #+LaTeX_CLASS: beamer in org files
  334. (unless (boundp 'org-export-latex-classes)
  335. (setq org-export-latex-classes nil))
  336.  
  337. (add-to-list 'org-export-latex-classes
  338. ;; beamer class, for presentations
  339. '("beamer"
  340. "\\documentclass[11pt]{beamer}
  341. \\mode<{{{beamermode}}}>
  342. \\usetheme{{{{beamertheme}}}}
  343. \\setbeamercovered{{{{transparent}}}}
  344. \\usecolortheme{{{{beamercolortheme}}}}
  345. \\usepackage[spanish]{babel}
  346. %% \\beamertemplateballitem
  347. %% \\setbeameroption{show notes}
  348. \\usepackage[utf8]{inputenc}
  349. \\usepackage[T1]{fontenc}
  350. \\usepackage{hyperref}
  351. \\usepackage{color}
  352. \\usepackage{listings}
  353. \\usepackage{alltt}
  354. \\usepackage{verbatim}
  355. \\usepackage{hyperref}
  356. \\usepackage{array}
  357. %% ulem nos da mayor control de subrayados, \\normalem evita que todos
  358. %% los \\em sean subrayados
  359. \\usepackage{ulem}
  360. \\normalem
  361. %% \\lstset{numbers=none,language=[ISO]C++,tabsize=4,
  362. %% frame=single,
  363. %% basicstyle=\\small,
  364. %% showspaces=false,showstringspaces=false,
  365. %% showtabs=false,
  366. %% keywordstyle=\\color{blue}\\bfseries,
  367. %% commentstyle=\\color{red},
  368. %% }
  369.  
  370. \\newcommand{\\confurl}{\\url{{{{beamerconfurl}}}}}
  371.  
  372. \\institute{{{{beamerinstitute}}}}
  373. \\subject{{{{beamersubject}}}}"
  374.  
  375. ("\\section{%s}" . "\\section*{%s}")
  376.  
  377. ("\\begin{frame}[fragile]\\frametitle{%s}"
  378. "\\end{frame}"
  379. "\\begin{frame}[fragile]\\frametitle{%s}"
  380. "\\end{frame}")))
  381.  
  382. ;; letter class, for formal letters
  383.  
  384. (add-to-list 'org-export-latex-classes
  385.  
  386. '("letter"
  387. "\\documentclass[11pt]{letter}
  388. \\usepackage[utf8]{inputenc}
  389. \\usepackage[T1]{fontenc}
  390. \\usepackage{color}"
  391. ("\\section{%s}" . "\\section*{%s}")
  392. ("\\subsection{%s}" . "\\subsection*{%s}")
  393. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  394. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  395. ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
  396.  
  397. ;; Exportación simple de org-mode a LaTeX (modo artículo)
  398. ;; Copiado de http://orgmode.org/worg/org-tutorials/org-latex-export.html
  399. (add-to-list 'org-export-latex-classes
  400. '("article"
  401. "\\documentclass{article}"
  402. ("\\section{%s}" . "\\section*{%s}")
  403. ("\\subsection{%s}" . "\\subsection*{%s}")
  404. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  405. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  406. ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
  407.  
  408. ;; En entornos `src' de org-mode, "fontificamos" en vivo según el
  409. ;; lenguaje especificado
  410. (setq org-src-fontify-natively t)
  411. ;; Y en la salida LaTeX
  412. (require 'org-latex)
  413. (setq org-export-latex-listings t)
  414. (if (not (boundp 'org-export-latex-packages-alist))
  415. (setq org-export-latex-packages-alist '()))
  416. (add-to-list 'org-export-latex-packages-alist '("" "listings"))
  417. (add-to-list 'org-export-latex-packages-alist '("" "color"))
  418.  
  419. ;; Mostramos en línea las imágenes bajo org-mode
  420. (iimage-mode)
  421. (add-to-list 'iimage-mode-image-regex-alist
  422. (cons (concat "\\[\\[file:\\(~?" iimage-mode-image-filename-regex
  423. "\\)\\]") 1))
  424.  
  425. (defun org-toggle-iimage-in-org ()
  426. "display images in your org file"
  427. (interactive)
  428. (if (face-underline-p 'org-link)
  429. (set-face-underline-p 'org-link nil)
  430. (set-face-underline-p 'org-link t))
  431. (iimage-mode))