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.

  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. ;; Si el nombre de dos archivos es igual, agrega el directorio para que el
  17. ;; nombre del buffer sea único
  18. (require 'uniquify)
  19. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  20.  
  21. ;; No me gustan los archivos de respaldo~ o con número VCS~1.0~ -
  22. ;; Guardo los respaldos automáticos en ~/.saves/
  23. (setq make-backup-files nil)
  24. (setq version-control 'never)
  25. (setq backup-by-copying t
  26. backup-directory-alist '(("." . "~/.saves"))
  27. delete-old-versions t
  28. kept-new-versions 6
  29. kept-old-versions 2
  30. version-control t)
  31.  
  32. ;; Mostrar número actual de línea y columna
  33. (setq line-number-mode t)
  34. (setq column-number-mode t)
  35. ;; Mostrar los bloques marcados mientras los estamos marcando
  36. (setq transient-mark-mode t)
  37. ;; La campana se ve, no se oye
  38. (setq visible-bell t)
  39. ;; No seguir agregando líneas en blanco al final
  40. (setq next-line-add-newlines nil)
  41. ;; Hacer scroll línea por línea
  42. (setq scroll-step 1)
  43. ;; Si tenemos un display separado verticalmente, también doblar líneas largas
  44. (setq truncate-partial-width-windows nil)
  45. ;; Agregar automáticamente fin de línea a los archivos
  46. (setq require-final-newline t)
  47. ;; El modo default para archivos nuevos es text-mode
  48. (setq default-major-mode 'text-mode)
  49. ;; Los archivos .tmpl, .rhtml y .html.erb son templates de HTML
  50. (setq auto-mode-alist (cons '("tmpl$" . html-mode) auto-mode-alist))
  51. (setq auto-mode-alist (cons '("rhtml$" . html-mode) auto-mode-alist))
  52. (setq auto-mode-alist (cons '("html.erb$" . html-mode) auto-mode-alist))
  53. ;; Los archivos .t son tests de Perl
  54. (setq auto-mode-alist (cons '("\\\.t$" . perl-mode) auto-mode-alist))
  55. ;; Los archivos llamados /tmp/mutt* son abiertos en mail-mode
  56. (setq auto-mode-alist (cons '("^/tmp/mutt" . mail-mode) auto-mode-alist))
  57. ;; .emacs es abierto en lisp-mode
  58. (setq auto-mode-alist (cons '(".emacs$" . lisp-mode) auto-mode-alist))
  59. ;; Cuando hacemos un diff, que sea en modo unified
  60. (setq diff-switches '-u)
  61. ;; No me gusta perder un par de líneas gracias al toolbar..
  62. (setq tool-bar-mode nil)
  63. ;; Muestra como título de la ventana/icono el nombre del archivo abierto
  64. ;; (%f - filename, más largo. %b - buffer, más corto)
  65. (setq frame-title-format "Emacs - %f")
  66. (setq icon-title-format "Emacs - %b")
  67. ;; Seguimos ligas simbólicas aún si apuntan a un archivo controlado por CVS
  68. (setq vc-follow-symlinks t)
  69. ;; Recordamos nuestra posición en el buffer
  70. (setq save-place t)
  71. ;; Evitamos el splash screen al cargar, no sirve de nada...
  72. (setq inhibit-startup-message t)
  73.  
  74. ;; Los buffers en text-mode y mail-mode tienen activado auto-fill
  75. (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
  76. (add-hook 'mail-mode-hook '(lambda () (auto-fill-mode 1)))
  77.  
  78. ;; Si tenemos mouse con ruedita de scroll, habilítala
  79. (cond (window-system
  80. (mwheel-install)
  81. ))
  82.  
  83. ;; Si estoy desde consola, no quiero barra de menú
  84. (if (not window-system) (menu-bar-mode -1))
  85.  
  86. ;; Para poder teclear caracteres acentuados al usar en consola
  87. (set-input-mode nil nil 1)
  88.  
  89. ;; Acepta 'y' o 'n' cuando pide 'yes' o 'no'
  90. (fset 'yes-or-no-p 'y-or-n-p)
  91.  
  92. ;; Combinaciones útiles de teclas
  93. (global-set-key "\C-x\." 'kill-this-buffer)
  94. (global-set-key [(C-tab)] 'bury-buffer)
  95. (global-set-key "\C-cg" 'goto-line)
  96.  
  97. ;; Ctrl-Z es una joda - Se va
  98. (global-unset-key "\C-z")
  99.  
  100.  
  101. ;;;;; La siguiente sección (mmm) fue tomada de:
  102. ;;;;; <a href="http://www2.ecos.de/~mailarc/embperl/2004-03/msg00078.html</p>
  103. <p>;;" title="http://www2.ecos.de/~mailarc/embperl/2004-03/msg00078.html</p>
  104. <p>;;">http://www2.ecos.de/~mailarc/embperl/2004-03/msg00078.html</p>
  105. <p>;;</a> needed for all mmm usage
  106. (require 'mmm-vars)
  107.  
  108. ;; needed for mmm automatic mode
  109. (require 'mmm-auto)
  110.  
  111. ;; needed for Embperl
  112. (require 'mmm-sample)
  113.  
  114. ;; now we setup mmm to automatically appear - if it is called for
  115. (setq mmm-global-mode 'maybe)
  116.  
  117. ;; ;; I don't like background colors in my perl sections, so '0' turns
  118. ;; ;; off all background fiddling. Up to you. See 'info mmm'.
  119. ;; (setq mmm-submode-decoration-level 0)
  120. (setq mmm-submode-decoration-level 2)
  121.  
  122. ;; mmm sets perl sections to use cperl-mode by default. I perfer
  123. ;; plain perl-mode, so I include the following. Up to you.
  124. (mmm-add-to-major-mode-preferences 'perl 'perl-mode t)
  125.  
  126. ;; Here force any oddball extensions used by Embperl to html
  127. ;; I use ".epl".
  128. (setq auto-mode-alist
  129. (append
  130. ;; File name ends in '.epl'.
  131. '(
  132. ("\\.epl\\'" . html-mode))
  133. auto-mode-alist))
  134.  
  135.  
  136. ;; If you want automatic Embperl mmm mode for certain files
  137. ;; (you can select with a regex on name/extension or directory -
  138. ;; see 'info mmm'), include lines similar to the following:
  139.  
  140. (mmm-add-mode-ext-class nil "\\.epl\\'" 'embperl)
  141. (mmm-add-mode-ext-class nil "\\.html\\'" 'embperl)
  142.  
  143. ;; if you use the above lines, no 'mode' line is required in the
  144. ;; source file.
  145.  
  146. (set-face-background 'mmm-special-submode-face "#000099")
  147. (set-face-background 'mmm-output-submode-face "#000079")
  148. (set-face-background 'mmm-comment-submode-face "#000059")
  149. (set-face-background 'mmm-code-submode-face "#000039")
  150. (set-face-background 'mmm-init-submode-face "#000019")
  151. ;;(set-face-foreground 'mmm-output-submode-face "Black")
  152. ;;(set-face-foreground 'mmm-code-submode-face "Black")
  153. ;;(set-face-foreground 'mmm-comment-submode-face "Red")
  154.  
  155. ;;; Modo MMM para RHTML (Ruby on Rails)
  156. ;;; Tomado de <a href="http://blog.cosinux.org/2006/06/13/emacs-and-ruby-on-rails<br />
  157. ;;;" title="http://blog.cosinux.org/2006/06/13/emacs-and-ruby-on-rails<br />
  158. ;;;">http://blog.cosinux.org/2006/06/13/emacs-and-ruby-on-rails<br />
  159. ;;;</a> (y recortado - MMM fue activado más arriba)
  160. (mmm-add-classes
  161. '((erb-code
  162. :submode ruby-mode
  163. :match-face (("<%#" . mmm-comment-submode-face)
  164. ("<%=" . mmm-output-submode-face)
  165. ("<%" . mmm-code-submode-face))
  166. :front "<%[#=]?"
  167. :back "%>"
  168. :insert ((?% erb-code nil @ "<%" @ " " _ " " @ "%>" @)
  169. (?# erb-comment nil @ "<%#" @ " " _ " " @ "%>" @)
  170. (?= erb-expression nil @ "<%=" @ " " _ " " @ "%>" @))
  171. )))
  172. (add-hook 'html-mode-hook
  173. (lambda ()
  174. (setq mmm-classes '(erb-code))
  175. (mmm-mode-on)))
  176. (add-to-list 'auto-mode-alist '("\\.rhtml$" . html-mode))
  177.  
  178. ;;;
  179. ;; rails mode
  180. (defun try-complete-abbrev (old)
  181. (if (expand-abbrev) t nil))
  182.  
  183. (setq hippie-expand-try-functions-list
  184. '(try-complete-abbrev
  185. try-complete-file-name
  186. try-expand-dabbrev))
  187.  
  188. (custom-set-faces
  189. ;; custom-set-faces was added by Custom.
  190. ;; If you edit it by hand, you could mess it up, so be careful.
  191. ;; Your init file should contain only one such instance.
  192. ;; If there is more than one, they won't work right.
  193. '(mmm-cleanup-submode-face ((t (:background "#000000"))))
  194. '(mmm-code-submode-face ((t (:background "#000039"))))
  195. '(mmm-comment-submode-face ((t (:background "#590000"))))
  196. '(mmm-declaration-submode-face ((t (:background "#0000A9"))))
  197. '(mmm-default-submode-face ((t (:background "#000079"))))
  198. '(mmm-init-submode-face ((t (:background "#000019"))))
  199. '(mmm-output-submode-face ((t (:background "#000079")))))
  200.  
  201. ;; convert dos (^M) end of line to unix end of line (and viceversa)
  202. (defun dos2unix()
  203. (interactive)
  204. (goto-char(point-min))
  205. (while (search-forward "\r" nil t)
  206. (replace-match "")
  207. )
  208. )
  209.  
  210. (defun unix2dos()
  211. (interactive)
  212. (goto-char(point-min))
  213. (while (search-forward "\n" nil t)
  214. (replace-match "\r\n")
  215. )
  216. )
  217. (custom-set-variables
  218. ;; custom-set-variables was added by Custom.
  219. ;; If you edit it by hand, you could mess it up, so be careful.
  220. ;; Your init file should contain only one such instance.
  221. ;; If there is more than one, they won't work right.
  222. '(column-number-mode t)
  223. '(show-paren-mode t)
  224. '(tool-bar-mode nil)
  225. '(transient-mark-mode t))