暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
drymer 58dbd00f06 Usar evil-define-key en vez de define-key 1 年之前
files Usar evil-define-key en vez de define-key 1 年之前
meta Add meta 2 年之前
tasks Initial commit 2 年之前
.gitignore Initial commit 2 年之前
README.md Añadir paquetes genéricos 1 年之前
TODO.org Añadir TODO y guardar mas ficheros recentf 1 年之前

README.md

Índice

  1. Tabla de contenido:TOC_5_org:
  2. Acerca de este documento
  3. Configuración Genérica
    1. Iniciar paquetes elpa/melpa/marmalade
    2. Actualizar paquetes
    3. Asegurarse de que use-package y el-get estan instalados y los inicializa
      1. Hábitos
    4. Moverse por el buffer
    5. Establecer nombre y correo
    6. Abrir cómo buffer inicial
    7. Iniciar cómo servidor
    8. Destacar el par coincidente
    9. Auto-guardado
    10. Modo por defecto
    11. Acepta ‘y’ o ‘n’ cuando pide ‘yes’ o ‘no’
    12. Lenguaje por defecto en emacs y org-mode
    13. Moverse por ventanas con shift
    14. Helm
      1. Buscar más eficazmente en Helm
    15. ivy-mode
      1. counsel-dash
      2. ace-isearch
    16. Seguir enlaces simbólicos
    17. Emparejar parentesis y otros
    18. Mantener lista de buffers recientes
    19. Guardar el layout tal cómo está
    20. No truncar líneas
    21. Programación
      1. Auto identación
      2. Magit
      3. Insertar licencia
      4. Auto-competado
    22. Borrar espacios sobrantes
    23. Usar ssh con tramp
    24. Golden Ratio
    25. Abrir enlaces en el navegador por defecto
    26. Terminal
    27. Cambiar de ventana más comodamente
    28. undo-tree
    29. Sobreescribir al seleccionar texto
    30. Buffer ∗Scratch∗ persistente
    31. kill-this-buffer en vez de kill-buffer
    32. Projectile
    33. Ispell
    34. Paquetes genéricos
      1. Imenu
      2. Hydra
      3. csv-mode
      4. Paleta de colores
      5. Hacer gifs con camcorder.el
      6. Mostrar teclas presionadas en un buffer
      7. Hardcodear atajos de teclado
      8. Flycheck
      9. Rainbow-mode
      10. i3wm-config-mode
      11. Lorem Ipsum
      12. Pastear en sprunge.us
      13. ansible-doc
      14. emacs-purpose
      15. Yasnippet
      16. which-key
      17. rainbow-mode
      18. ox-reveal
      19. lua-mode
      20. kanban.el
      21. multiple-cursors
      22. Terraform
      23. hideshow
  4. Aspecto
    1. Tema cyberpunk
    2. Powerline modificada
    3. Formato de las columnas de númeracion
    4. Ventana limpia
    5. UTF-8
    6. Tipo de fuente
    7. Partir buffers de manera más bonita
    8. Scroll
    9. Aumentar y disminuir tamaño de la fuente
  5. Configuración por modos o lenguajes
    1. JSON
    2. Haskel
    3. Markdown
    4. Python
    5. web-mode
    6. DockerFile
    7. kivy-mode
    8. gnu-social-mode
    9. po-mode
    10. org-mode
      1. Definir fuente de el-get
      2. Agenda
      3. Edición, diseño y varios
    11. mail-mode
    12. lisp
      1. Paredit
      2. package-lint
      3. rainbow-delimiters
    13. compile-mode
  6. Funciones personalizadas
    1. Recargar todos los buffers abiertos
    2. Insertar cabeceras para org-mode
    3. Insertar bloque src para org-mode
    4. Insertar org-entities
    5. Añadir soporte para editar archivos en docker
    6. Insertar fecha de hoy
    7. Abrir eshell aquí
    8. Reabrir buffer con sudo

Tabla de contenido :TOC_5_org:

Acerca de este documento

Este documento está hecho en org-mode y es tanto mi configuración de emacs como la explicación de esta. Más información sobre esto aquí.

Mi idea es que termine siendo más o menos un tutorial de emacs, tal vez extendido con los articulos del blog. A ver como sale. Se puede instalar mi configuración de emacs del siguiente modo:

git clone https://daemons.it/cgit/dotfiles
cd dotfiles
./instala.sh emacs

Que hace esto exactamente? Básicamente, instalar todos los paquetes y scripts mencionados en este documento. De un modo más extendido, lo que hace el script de instala.sh es esto (la explicación en los comentarios):

# Establece el directorio de las configuraciones, lo crea y las copia ahí
EMACSDIR="$HOME/.emacs.d"
mkdir -p $EMACSDIR
ln -sf $(pwd)/emacs.d/{init.el,init-literate.org} $EMACSDIR

# crear private-literate.org si no existe para que no se queje init.el
if [[ ! -e $EMACSDIR/private-literate.org ]]
then
    echo -e "* Vacio\n#+BEGIN_SRC emacs-lisp\n#+END_SRC" > $EMACSDIR/private-literate.org
fi

# Instalar todos los paquetes de emacs
emacs -Q --batch --eval "(load-file \""$EMACSDIR/"init.el\")"
emacs -Q --batch --eval "(load-file \""$EMACSDIR/"init-literate.el\")"
emacs -Q --batch --eval "(load-file \"/tmp/powerline.el\"))"

# Por algún motivo al compilar desde el-get mete una ruta incorrecta en org-loaddefs.el
sed -i "s,org-mode-maint/lisp/,,g" $EMACSDIR/el-get/org-mode-maint/lisp/org-loaddefs.el

# Necesito permiso de superusuario para copiar los scripts capture y demacs en /usr/local/bin/
sudo ln -sf $(pwd)/emacs.d/{capture,demacs} /usr/local/bin/

Este archivo en formato org-mode está aquí. Este archivo en formato HTML está aquí.

Configuración Genérica

En esta sección se tocará la configuración que tenga que ver con el manejo general de emacs. Yo suelo arrancar emacs usando un script que llamo demacs. En el llamo a emacs en modo demonio para que quede corriendo en segundo plano y luego abro emacsclient. Que ventajas tiene esto? Si por lo que sea petan las X, emacs sigue corriendo, por ejemplo. O que puedo no tener ninguna ventana de emacs abierta y aún así no perder las ventanas que hay en ellas. O mejor aún, que puedo usarlo desde terminal como editor de mutt.

El script que uso es el siguiente:

#!/bin/bash

USERID=`id -u`
if [[ ! -e /tmp/emacs$USERID/server ]]
then
    emacs --daemon
    emacsclient -c -n -e '(load-file "/tmp/powerline.el")' -e "(org-agenda-list)"
else
    emacsclient -c -n -e "(org-agenda-list)"
fi

Me gusta que nada más abrirlo, me muestre la agenda, por eso está el (org-agenda-list). El load-file al fichero del powerline es debido a que emacs al lanzarse en modo demonio, es como si se lanzase en modo terminal, por lo que hay ciertos paquetes que los carga como tal. Y dado que el powerline que uso es un poco especialito, si no se arranca desde la gui, se ve feo. Por ello la primera vez que se ejecute el emacsclient, evalua el powerline.

Iniciar paquetes elpa/melpa/marmalade

Ahora mismo el repositorio de marmalade está comentado por que da un error al usarlo con https. Uso el de ojab.ru, que es un proxy a marmalade.

(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
             ("marmalade" . "https://ojab.ru/marmalade/")
             ("melpa" . "https://melpa.org/packages/")))
(package-initialize)

Actualizar paquetes

(package-refresh-contents)

Asegurarse de que use-package y el-get estan instalados y los inicializa

;; Comprueba si use-package está instalado, sinó lo instala desde los repositorios
(unless (require 'use-package nil 'noerror)
  (package-install 'use-package))

(require 'use-package)

;; Añade la ruta de el-get
(add-to-list 'load-path (concat user-emacs-directory "el-get/el-get/"))

;; Comprueba si el-get está instalado, sinó lo instala desde un gist
(unless (require 'el-get nil 'noerror)
  ;; comprobar si existe el fichero a descargar, si existe no lo descarga
  (if (not (file-exists-p "/tmp/el-get-install.el"))
      (url-copy-file "https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el" "/tmp/el-get-install.el"))
  (load-file "/tmp/el-get-install.el"))

(use-package el-get)

Hábitos

(use-package org-habit
  :init
  (add-to-list 'org-modules 'org-habit)
    :config
    (setq org-habit-preceding-days 7
          org-habit-following-days 0
          org-habit-graph-column 50
          org-habit-show-habits-only-for-today t
          org-habit-show-all-today t))

Moverse por el buffer

Subir y bajar párrafos:

(global-set-key "\M-p" 'backward-paragraph)
(global-set-key "\M-n" 'forward-paragraph)

Establecer nombre y correo

Al exportar en org-mode, por ejemplo, coge estos valores.

(setq user-full-name "drymer"
      user-mail-address "drymer [ EN ] autistici.org")

Abrir cómo buffer inicial

(setq initial-buffer-choice "~/Documentos/org/index.org")

Iniciar cómo servidor

De este modo puedo usar emacsclient desde la terminal y la sesión de emacs existente.

(server-start)

Destacar el par coincidente

(show-paren-mode)

Auto-guardado

Es bastante molesto que te vaya dejando la mierda por ahí, mejor en un directorio conjunto.

(defvar backup-dir (expand-file-name (concat user-emacs-directory "backup/")))
(defvar autosave-dir (expand-file-name (concat user-emacs-directory "backup/")))
(setq backup-directory-alist (list (cons ".*" backup-dir)))
(setq auto-save-list-file-prefix autosave-dir)
(setq auto-save-file-name-transforms `((".*" ,autosave-dir t)))
(setq tramp-backup-directory-alist backup-directory-alist)
(setq tramp-auto-save-directory autosave-dir)

Modo por defecto

Al abrir un archivo o bufer sin algún modo asociado, se abrirá en modo texto.

(setq major-mode 'text-mode)

Acepta ‘y’ o ‘n’ cuando pide ‘yes’ o ‘no’

(fset 'yes-or-no-p 'y-or-n-p)

Lenguaje por defecto en emacs y org-mode

(setq current-language-environment "Spanish")
(setq org-export-default-language "es")

Moverse por ventanas con shift

No funciona en org-mode.

(when (fboundp 'windmove-default-keybindings)
  (windmove-default-keybindings))

Helm

Copiado del git de helm. Esta es una configuración bastante mínima. Más información por aquí. Está activo, pero solo para couns el-dash.

(require 'helm)
(require 'helm-config)

(global-set-key (kbd "C-c h") 'helm-command-prefix)
(global-unset-key (kbd "C-x c"))

(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action)
(define-key helm-map (kbd "C-z")  'helm-select-action)

(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x b") 'helm-mini)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "M-x") 'helm-M-x)

(helm-mode 1)

(require 'helm-descbinds)
(helm-descbinds-mode)

Buscar más eficazmente en Helm

Más información en este articulo. Desactivado actualmente.

(global-ace-isearch-mode +1)
(custom-set-variables
 '(ace-isearch-input-length 7)
 '(ace-isearch-jump-delay 0.25)
 '(ace-isearch-function 'avy-goto-char)
 '(ace-isearch-use-jump 'printing-char))

ivy-mode

Ivy es más liviano que helm, aunque más simple. Más información aquí.

(unless (require 'ivy nil 'noerror)
  (sleep-for 5))

(use-package ivy
  :init
  ;; Añade los buffers de bookmarks y de recentf
  (setq ivy-use-virtual-buffers t)
  ;; Muestra las coincidencias con lo que se escribe y la posicion en estas
  (setq ivy-count-format "(%d/%d) ")
  ;; Un mejor buscador
  (setq ivy-re-builders-alist
    '((read-file-name-internal . ivy--regex-fuzzy)
      (t . ivy--regex-plus)))
  ;; No se sale del minibuffer si se encuentra un error
  (setq ivy-on-del-error-function nil)
  ;; ivy mete el simbolo ^ al ejecutar algunas ordenes, así se quita
  (setq ivy-initial-inputs-alist nil)
  ;; Dar la vuelta a los candidatos
  (setq ivy-wrap t)
  ;; Ver la ruta de los ficheros virtuales
  (setq ivy-virtual-abbreviate 'full)
    ;; Asegurarse de que están smex, flx, diminis y ivi-hydra
  (use-package smex :ensure t)
  (use-package flx :ensure t)
  (use-package diminish :ensure t)
  (use-package ivy-hydra :ensure t)
  :bind
  ("C-c C-r" . ivy-resume)
  :config
  (ivy-mode 1)
  (setq magit-completing-read-function 'ivy-completing-read)
  :diminish ivy-mode
  :ensure t)


(use-package counsel
  :bind (;; Sustituir M-x
     ("M-x" . counsel-M-x)
     ;; Sustituir imenu
     ("C-c b" . counsel-imenu)
     ;; Sustituir find-file
     ("C-x C-f" . counsel-find-file)
     ;; Abrir ficheros del repo git
     ("C-x f" . counsel-git)
     ;; Sustituir describe-function
     ("C-h f" . counsel-describe-function)
     ;; Sustituir describe-variable
     ("C-h v" . counsel-describe-variable)
     ;; Sustituir descbinds
     ("C-h b" . counsel-descbinds)
     ;; Sustituye helm-show-kill-ring
     ("M-y" . counsel-yank-pop)
     ("C-c C-k" . counsel-ag)
     :map ivy-minibuffer-map
     ("M-y" . ivy-next-line-and-call)
     ("C-c C-r" . ivy-resume)
     :map org-mode-map
     ("C-c C-q" . counsel-org-tag))
     :config
     ;; usar ffap
     (setq counsel-find-file-at-point t)
     :ensure t)

(use-package swiper
  ;; comentado en favor de ace-isearch
  ;; :bind (;; Sustituir isearch
  ;;     ("C-s" . swiper)
  ;;     ("C-r" . swiper))
  :ensure t)

counsel-dash

(add-to-list 'el-get-sources '(:name counsel-dash
                     :description "counsel-dash"
                     :type github
                     :pkgname "nathankot/counsel-dash"))

(if (not (el-get-package-installed-p 'counsel-dash))
  (progn
    (package-install 'helm)
    (package-install 'dash-functional)
    (package-install 'helm-dash)
    (el-get 'sync 'counsel-dash)))

(use-package counsel-dash
  :load-path "el-get/counsel-dash"
  :init
  (setq counsel-dash-docsets-path "~/.emacs.d/docsets/")
  (setq helm-dash-docsets-path counsel-dash-docsets-path)
  (setq counsel-dash-common-docsets '("Bash" "Emacs Lisp" "HTML" "Markdown" "Nginx" "Python 3" "Docker" "Font_Awesome" "LaTeX" "MySQL" "Python 2" "SQLite" "Ansible" "Apache_HTTP_Server" "HTML" "Nginx"))
  (setq counsel-dash-browser-func 'eww))

Auto-instala los docsets:

(if (not (concat counsel-dash-docsets-path "Bash.docset"))
    (let ((local_docsets counsel-dash-common-docsets)
      (docs))
      (while local_docsets
    (setq docs (car local_docsets))
    (if (string-match "Python" docs)
        (setq docs (replace-regexp-in-string " " "_" docs)))
    (if (string-match "Emacs Lisp" docs)
        (setq docs (replace-regexp-in-string " " "_" docs)))
    (if (not (file-exists-p (concat counsel-dash-docsets-path "/" (car local_docsets) ".docset")))
        (progn
          (counsel-dash-install-docset docs)
          (setq local_docsets (cdr local_docsets)))
      (setq local_docsets (cdr local_docsets))))))

ace-isearch

(use-package ace-isearch
  :ensure t
  :init
  ;; Dependencias
  ;; (use-package helm-swoop :ensure t)
  (use-package avy
    :ensure t
    :config
    (setq avy-all-windows t))
  ;; (use-package ace-jump-mode :ensure t)
  :config
  (setq avy-background t)
  (setq ace-isearch-function 'avy-goto-char)
  (setq ace-isearch-input-length 5)
  (setq ace-isearch-jump-delay 0.30)
  (setq ace-isearch-use-jump 'printing-char)
  (setq ace-isearch-function-from-isearch 'ace-isearch-swiper-from-isearch)
  (global-ace-isearch-mode +1)
  :bind (:map isearch-mode-map
          ("C-'" . avy-isearch))
  :diminish ace-isearch-mode)

Seguir enlaces simbólicos

(setq vc-follow-symlinks t)

Emparejar parentesis y otros

Empareja () [] {} y “”.

(electric-pair-mode 1)

Mantener lista de buffers recientes

Al usar ivy o helm y ejecutar switch-buffer (C-x b) se pueden ver los buffers que se han abierto recientemente si se tiene recentf activo.

(setq recentf-max-saved-items 30)
(setq recentf-max-menu-items 20)
(recentf-mode 1)

Guardar el layout tal cómo está

(desktop-save-mode 1)

No truncar líneas

(setq truncate-lines nil)

Programación

Auto identación

(global-set-key (kbd "RET") 'newline-and-indent)

Magit

(use-package magit
  :bind
  ("C-x g" . magit-status)
  :config
  ;; usar un wrapper que torifica git
  (setq magit-git-executable "tgit")
  :ensure t)

El wrapper es el siguiente:

#!/bin/bash

git "$@"

Insertar licencia

(add-to-list 'el-get-sources '(:name xlicense-github
                     :type github
                     :pkgname "jtimberman/xlicense-el"))

(if (not (el-get-package-installed-p 'xlicense-github))
    (el-get 'sync 'xlicense-github))

(use-package xlicense
  :load-path "el-get/xlicense-github"
  :init
  (setq license-directory (concat user-emacs-directory "el-get/xlicense-github/licenses/")))

Auto-competado

(use-package company
  :ensure t
  :config
  (add-hook 'after-init-hook 'global-company-mode)
  (use-package company-ansible :ensure t :config (add-to-list 'company-backends 'company-ansible))
  (use-package company-jedi :ensure t :config (add-to-list 'company-backends 'company-jedi))
  :bind ("A-TAB" . company-complete)
  :diminish company-mode)

Borrar espacios sobrantes

Al guardar, borrar los que sobren de cada linea despues de el último carácter.

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Usar ssh con tramp

Por defecto usa scp, que es muy lento. Así se usará ssh.

(setq tramp-default-method "ssh")

Golden Ratio

Gestiona las ventanas abiertas modificando el tamaño para hacerlo aceptable. Ignora los buffers concretados en la variable golden-ratio-exclude-buffer-regexp.

(use-package golden-ratio
  :config
  ;; (defun init/no-golden-ratio-for-buffers (bufname)
  ;;   "Disable golden-ratio if BUFNAME is the name of a visible buffer."
  ;;   (and (get-buffer bufname) (get-buffer-window bufname 'visible)))
  ;; (defun init/no-golden-ratio ()
  ;;   "Disable golden-ratio for guide-key popwin buffer."
  ;;   (or (init/no-golden-ratio-for-buffers " *undo-tree*")
  ;;       (init/no-golden-ratio-for-buffers " *undo-tree Diff*")
  ;;       ))

  ;; (add-to-list 'golden-ratio-inhibit-functions
  ;;              'init/no-golden-ratio)

  (golden-ratio-mode t)
  (setq golden-ratio-exclude-buffer-regexp '("undo-tree" "help" "diff" "calendar" "messages" "Org Agenda" "Agenda Commands" "Org Select" "magit:" "Calendar"))
  (setq golden-ratio-auto-scale t)
  :diminish golden-ratio-mode
  :ensure t)

Abrir enlaces en el navegador por defecto

Para establecer un navegador por defecto, hay ejecutar:

xdg-settings set default-web-browser qutebrowser.desktop

En general, cada navegador te lo crea. En el caso de qutebrowser esto no fue así, por lo que tuve que copiar el de firefox en /usr/share/applications/qutebrowser.desktop que contiene:

cat /usr/share/applications/qutebrowser.desktop

La configuración necesaria para emacs es la siguiente:

(setq browse-url-browser-function 'browse-url-xdg-open)

Terminal

Establecer shell.

(setq explicit-shell-file-name "/bin/bash")
(setq shell-file-name explicit-shell-file-name)
(setenv "SHELL" shell-file-name)
(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m)

Cambiar de ventana más comodamente

Antes usaba esto:

(use-package switch-window
  :ensure t
  :bind ("C-x o" . switch-window))

Ahora uso esto:

(use-package ace-window
  :ensure t
  :bind
  ("C-x o" . ace-window)
  :config
  (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))

undo-tree

Visualiza los cambios hechos con un arbol. Además, cuando se tira para atras y se hace un cambio, los primeros siguen accesibles.

(use-package undo-tree
  :diminish undo-tree-mode
  :ensure t
  :config
  (global-undo-tree-mode)
  (setq undo-tree-visualizer-timestamps t))

Sobreescribir al seleccionar texto

No está activo.

(delete-selection-mode t)

Buffer ∗Scratch∗ persistente

(use-package persistent-scratch
  :ensure t
  :config
  (persistent-scratch-setup-default))

kill-this-buffer en vez de kill-buffer

Fuente: http://pragmaticemacs.com/emacs/dont-kill-buffer-kill-this-buffer-instead/

(global-set-key (kbd "C-x k") 'kill-this-buffer)

Projectile

(use-package projectile
  :ensure t
  :config
  (use-package counsel-projectile
  :ensure t
  :config
  (counsel-projectile-on))
  (projectile-mode)
  (setq projectile-switch-project-action #'counsel-projectile-find-file)
  :diminish projectile-mode)

Ispell

Instalamos el diccionario de esta dirección y configuramos emacs para que lo use:

(setq ispell-dictionary "español")

Paquetes genéricos

Aquí van los paquetes que apenas uso o que no necesitan mucha configuración.

Imenu

Imenu sirver para crear menus de archivos, habitualmente usando las cabeceras.

  1. imenu-list

    Muestra imenu en un buffer lateral. No está activo.

    (use-package imenu-list
      :ensure t
      :bind ("C-'" . imenu-list-minor-mode)
      :config (setq imenu-list-auto-resize nil))
    

Hydra

(use-package hydra :ensure t)

csv-mode

(use-package csv-mode :ensure t)

Paleta de colores

(use-package palette
  :ensure t)

Hacer gifs con camcorder.el

(use-package camcorder
  :ensure t
  :config
  (setq camcorder-recording-command '("recordmydesktop" " --fps 100 --no-sound --windowid " window-id " -o " file)))

Mostrar teclas presionadas en un buffer

(use-package mwe-log-commands
  :ensure t)

Hardcodear atajos de teclado

Desactivado.

(use-package hardcore-mode
  :ensure t
  :config
  (global-set-key "\M-p" 'backward-paragraph)
  (global-set-key "\M-n" 'forward-paragraph)
  (define-key key-translation-map [?\C-h] [?\C-?])
  (global-set-key (kbd "<f1>") 'help-command)
  (define-key hardcore-mode-map
    (kbd "<C-up>") (lambda ()
               (interactive)
               (message "This key is disabled. Use M-p instead.")))
  (define-key hardcore-mode-map
    (kbd "<C-down>") (lambda ()
               (interactive)
               (message "This key is disabled. Use M-n instead.")))
  (define-key hardcore-mode-map
    (kbd "<C-left>") (lambda ()
               (interactive)
               (message "This key is disabled. Use M-b instead.")))
  (define-key hardcore-mode-map
    (kbd "<C-right>") (lambda ()
               (interactive)
               (message "This key is disabled. Use M-f instead.")))
  (define-key hardcore-mode-map
    (kbd "<prior>") (lambda ()
            (interactive)
            (message "This key is disabled. Use M-v instead.")))
  (define-key hardcore-mode-map
    (kbd "<next>") (lambda ()
            (interactive)
            (message "This key is disabled. Use C-v instead.")))
  (define-key hardcore-mode-map
    (kbd "<home>") (lambda ()
            (interactive)
            (message "This key is disabled. Use C-a instead.")))
  (define-key hardcore-mode-map
    (kbd "<C-home>") (lambda ()
            (interactive)
            (message "This key is disabled. Use M-< instead.")))
  (define-key hardcore-mode-map
    (kbd "<end>") (lambda ()
            (interactive)
            (message "This key is disabled. Use C-e instead.")))
  (define-key hardcore-mode-map
    (kbd "<C-end>") (lambda ()
            (interactive)
            (message "This key is disabled. Use M-> instead.")))
  (global-hardcore-mode))

Flycheck

Corrector

(use-package flycheck
  :ensure t
  :config (global-flycheck-mode))

Rainbow-mode

Muestra los colores de paletas HTML (hexadecimal) con el color que representa.

(use-package rainbow-mode
  :ensure t)

i3wm-config-mode

Muestra colores para la configuración de i3.

(add-to-list 'el-get-sources '(:name i3wm-config-mode
                     :type github
                     :pkgname "Alexander-Miller/i3wm-Config-Mode"))

(if (not (el-get-package-installed-p 'i3wm-config-mode))
    (el-get 'sync 'i3wm-config-mode))

(use-package i3wm-config-mode
  :load-path "el-get/i3wm-config-mode")

Lorem Ipsum

Inserta Lorem Ipsum.

(if (not (el-get-package-installed-p 'lorem-ipsum))
    (el-get 'sync 'lorem-ipsum))

(use-package lorem-ipsum
  :load-path "el-get/lorem-ipsum")

Pastear en sprunge.us

(add-to-list 'el-get-sources '(:name sprunge
                     :type github
                     :pkgname "tomjakubowski/sprunge.el"))

(if (not (el-get-package-installed-p 'sprunge))
    (el-get 'sync 'sprunge))

(use-package sprunge
  :init
  (use-package request :ensure t)
  :load-path "el-get/sprunge")

ansible-doc

(use-package ansible-doc
  :ensure t
  :config
  (add-hook 'yaml-mode-hook #'ansible-doc-mode)
  ;; Carga los módulos para no tener que esperar
  (async-start
   `(lambda()
      (save-window-excursion
    (ansible-doc "apt")))))

emacs-purpose

(use-package window-purpose
  :ensure t
  :init
  (use-package ivy-purpose :ensure t :config (ivy-purpose-setup))
  (use-package window-purpose-x :config (purpose-x-golden-ratio-setup))
  (setq purpose-user-mode-purposes
    '((python-mode . py)
      (inferior-python-mode . py-int)
      (org-mode . org)))
  (setq purpose-user-name-purposes
    '(("index.org" . agenda)
      ("index.org_archive" . agenda)
      ("web.org" . agenda)
      ("notas.org" . agenda)
      (" *command-log*" . command)))
  (purpose-compile-user-configuration)
  :config
  ;; https://github.com/bmag/ivy-purpose/issues/1
  (define-purpose-prefix-overload purpose-switch-buffer-overload
    '(ivy-switch-buffer
      switch-buffer-without-purpose
      purpose-switch-buffer-with-purpose))
  (purpose-mode))

Yasnippet

Desactivado.

(use-package yasnippet
  :load-path "el-get/yasnippet/"
  :config
  (yas-global-mode)
  (setq yas-snippet-dirs
    '("~/.emacs.d/snippets"
      "~/.emacs.d/el-get/yasnippet/snippets/"
      "~/.emacs.d/el-get/yasnippet/yasmate/"))
  (add-to-list 'hippie-expand-try-functions-list 'yas-hippie-try-expand)
  (setq yas-prompt-functions '(yas-ido-prompt))
  :diminish
  yas-minor-mode)

which-key

(use-package which-key
  :ensure t
  :config
  (which-key-mode))

rainbow-mode

(use-package rainbow-mode :ensure t)

ox-reveal

(use-package ox-reveal :ensure t
  :config
  (setq org-reveal-root (concat (getenv "HOME") "/" "Instalados/reveal.js")))

lua-mode

(use-package lua-mode :ensure t)

kanban.el

(use-package kanban :ensure t)

multiple-cursors

(use-package multiple-cursors
  :ensure t
  :bind
  (("C-S-c C-S-c" . mc/edit-lines)
   ("C-c ma" . mc/mark-all-dwim)
   ("C-c mp" . mc/mark-previous-lines)
   ("C-c mn" . mc/mark-next-lines)
   ("C-c mP" . mc/mark-previous-like-this)
   ("C-c mN" . mc/mark-next-like-this))
)

Terraform

(use-package terraform-mode :ensure t
  :config
  (terraform-format-on-save-mode))
(use-package company-terraform :ensure t)

hideshow

Mostrar y esconder código.

(use-package hideshow
  :bind (("C-c <tab>" . hs-toggle-hiding))
  :config
  (hs-minor-mode))

Aspecto

Tema cyberpunk

(use-package cyberpunk-theme
  :config (load-theme 'cyberpunk t)
  :ensure t
  :init (custom-set-variables
         '(custom-safe-themes
           (quote
            ("71ecffba18621354a1be303687f33b84788e13f40141580fa81e7840752d31bf" default)))
         ))

Powerline modificada

Lo siguiente lo he cogido de la configuración de Dennis Ogbe, modificando sólo los colores (creo).

(use-package powerline
  :ensure t
  :config
  (progn (setq powerline-default-separator 'contour)
         (setq powerline-height 25))
  (setq powerline-default-separator-dir '(right . left))

  ;; first reset the faces that already exist
  (set-face-attribute 'mode-line nil
                      :foreground (face-attribute 'default :foreground)
                      :family "Fira Sans"
                      :weight 'bold
                      :background (face-attribute 'fringe :background))
  (set-face-attribute 'mode-line-inactive nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :background (face-attribute 'fringe :background)
                      :family "Fira Sans"
                      :weight 'bold
                      :box `(:line-width -2 :color ,(face-attribute 'fringe :background)))
  (set-face-attribute 'powerline-active1 nil
                      :background "gray30")
  (set-face-attribute 'powerline-inactive1 nil
                      :background (face-attribute 'default :background)
                      :box `(:line-width -2 :color ,(face-attribute 'fringe :background)))

  ;; these next faces are for the status indicator
  ;; read-only buffer
  (make-face 'mode-line-read-only-face)
  (make-face 'mode-line-read-only-inactive-face)
  (set-face-attribute 'mode-line-read-only-face nil
                      :foreground (face-attribute 'default :foreground)
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-read-only-inactive-face nil
                      :foreground (face-attribute 'default :foreground)
                      :inherit 'mode-line-inactive)

  ;; modified buffer
  (make-face 'mode-line-modified-face)
  (make-face 'mode-line-modified-inactive-face)
  (set-face-attribute 'mode-line-modified-face nil
                      :foreground (face-attribute 'default :background)
                      :background "#729FCF"
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-modified-inactive-face nil
                      :foreground (face-attribute 'default :background)
                      :background "#729FCF"
                      :inherit 'mode-line-inactive)

  ;; unmodified buffer
  (make-face 'mode-line-unmodified-face)
  (make-face 'mode-line-unmodified-inactive-face)
  (set-face-attribute 'mode-line-unmodified-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-unmodified-inactive-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'mode-line-inactive)

  ;; the remote indicator
  (make-face 'mode-line-remote-face)
  (make-face 'mode-line-remote-inactive-face)
  (set-face-attribute 'mode-line-remote-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :background (face-attribute 'default :background)
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-remote-inactive-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :background (face-attribute 'default :background)
                      :inherit 'mode-line-inactive)

  ;; the current file name
  (make-face 'mode-line-filename-face)
  (make-face 'mode-line-filename-inactive-face)
  (set-face-attribute 'mode-line-filename-face nil
                      :foreground "#729FCF"
                      :background (face-attribute 'default :background)
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-filename-inactive-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :background (face-attribute 'default :background)
                      :inherit 'mode-line-inactive)

  ;; the major mode name
  (make-face 'mode-line-major-mode-face)
  (make-face 'mode-line-major-mode-inactive-face)
  (set-face-attribute 'mode-line-major-mode-face nil
                      :foreground (face-attribute 'default :foreground)
                      :inherit 'powerline-active1)
  (set-face-attribute 'mode-line-major-mode-inactive-face nil
                      :box `(:line-width -2 :color ,(face-attribute 'fringe :background))
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'powerline-inactive1)

  ;; the minor mode name
  (make-face 'mode-line-minor-mode-face)
  (make-face 'mode-line-minor-mode-inactive-face)
  (set-face-attribute 'mode-line-minor-mode-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'powerline-active1)
  (set-face-attribute 'mode-line-minor-mode-inactive-face nil
                      :box `(:line-width -2 :color ,(face-attribute 'fringe :background))
                      :foreground (face-attribute 'powerline-inactive1 :background)
                      :inherit 'powerline-inactive1)

  ;; the position face
  (make-face 'mode-line-position-face)
  (make-face 'mode-line-position-inactive-face)
  (set-face-attribute 'mode-line-position-face nil
                      :background (face-attribute 'default :background)
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-position-inactive-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :background (face-attribute 'default :background)
                      :inherit 'mode-line-inactive)

  ;; the 80col warning face
  (make-face 'mode-line-80col-face)
  (make-face 'mode-line-80col-inactive-face)
  (set-face-attribute 'mode-line-80col-face nil
                      :background "#729FCF"
                      :foreground (face-attribute 'default :background)
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-80col-inactive-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :background (face-attribute 'default :background)
                      :inherit 'mode-line-inactive)

  ;; the buffer percentage face
  (make-face 'mode-line-percentage-face)
  (make-face 'mode-line-percentage-inactive-face)
  (set-face-attribute 'mode-line-percentage-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'mode-line)
  (set-face-attribute 'mode-line-percentage-inactive-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'mode-line-inactive)

  ;; the directory face
  (make-face 'mode-line-shell-dir-face)
  (make-face 'mode-line-shell-dir-inactive-face)
  (set-face-attribute 'mode-line-shell-dir-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'powerline-active1)
  (set-face-attribute 'mode-line-shell-dir-inactive-face nil
                      :foreground (face-attribute 'font-lock-comment-face :foreground)
                      :inherit 'powerline-inactive1)

  (defpowerline dennis-powerline-narrow
    (let (real-point-min real-point-max)
      (save-excursion
        (save-restriction
          (widen)
          (setq real-point-min (point-min) real-point-max (point-max))))
      (when (or (/= real-point-min (point-min))
                (/= real-point-max (point-max)))
        (propertize (concat (char-to-string #x2691) " Narrow")
                    'mouse-face 'mode-line-highlight
                    'help-echo "mouse-1: Remove narrowing from the current buffer"
                    'local-map (make-mode-line-mouse-map
                                'mouse-1 'mode-line-widen)))))

  (defpowerline dennis-powerline-vc
    (when (and (buffer-file-name (current-buffer)) vc-mode)
      (if window-system
          (let ((backend (vc-backend (buffer-file-name (current-buffer)))))
            (when backend
              (format "%s %s: %s"
                      (char-to-string #xe0a0)
                      backend
                      (vc-working-revision (buffer-file-name (current-buffer)) backend)))))))

  (setq-default
   mode-line-format
   '("%e"
     (:eval
      (let* ((active (powerline-selected-window-active))

             ;; toggle faces between active and inactive
             (mode-line (if active 'mode-line 'mode-line-inactive))
             (face1 (if active 'powerline-active1 'powerline-inactive1))
             (face2 (if active 'powerline-active2 'powerline-inactive2))
             (read-only-face (if active 'mode-line-read-only-face 'mode-line-read-only-inactive-face))
             (modified-face (if active 'mode-line-modified-face 'mode-line-modified-inactive-face))
             (unmodified-face (if active 'mode-line-unmodified-face 'mode-line-unmodified-inactive-face))
             (position-face (if active 'mode-line-position-face 'mode-line-position-inactive-face))
             (80col-face (if active 'mode-line-80col-face 'mode-line-80col-inactive-face))
             (major-mode-face (if active 'mode-line-major-mode-face 'mode-line-major-mode-inactive-face))
             (minor-mode-face (if active 'mode-line-minor-mode-face 'mode-line-minor-mode-inactive-face))
             (filename-face (if active 'mode-line-filename-face 'mode-line-filename-inactive-face))
             (percentage-face (if active 'mode-line-percentage-face 'mode-line-percentage-inactive-face))
             (remote-face (if active 'mode-line-remote-face 'mode-line-remote-inactive-face))
             (shell-dir-face (if active 'mode-line-shell-dir-face 'mode-line-shell-dir-inactive-face))

             ;; get the separators
             (separator-left (intern (format "powerline-%s-%s"
                                             (powerline-current-separator)
                                             (car powerline-default-separator-dir))))
             (separator-right (intern (format "powerline-%s-%s"
                                              (powerline-current-separator)
                                              (cdr powerline-default-separator-dir))))

             ;; the right side
             (rhs (list
                   (dennis-powerline-vc minor-mode-face 'r)
                   (funcall separator-right face1 position-face)
                   (powerline-raw " " position-face)
                   (powerline-raw (char-to-string #xe0a1) position-face)
                   (powerline-raw " " position-face)
                   (powerline-raw "%4l" position-face 'r)
                   ;; display a warning if we go above 80 columns
                   (if (>= (current-column) 80)
                       (funcall separator-right position-face 80col-face)
                     (powerline-raw (char-to-string #x2502) position-face))
                   (if (>= (current-column) 80)
                       (powerline-raw "%3c" 80col-face 'l)
                     (powerline-raw "%3c" position-face 'l))
                   (if (>= (current-column) 80)
                       (powerline-raw " " 80col-face)
                     (powerline-raw " " position-face))
                   (if (>= (current-column) 80)
                       (funcall separator-left 80col-face percentage-face)
                     (funcall separator-left position-face percentage-face))
                   (powerline-raw " " percentage-face)
                   (powerline-raw "%6p" percentage-face 'r)))

             ;; the left side
             (lhs (list
                   ;; this is the modified status indicator
                   (cond (buffer-read-only
                          (powerline-raw "  " read-only-face))
                         ((buffer-modified-p)
                          ;; do not light up when in an interactive buffer. Set
                          ;; ML-INTERACTIVE? in hooks for interactive buffers.
                          (if (not (bound-and-true-p ml-interactive?))
                              (powerline-raw "  " modified-face)
                            (powerline-raw "  " unmodified-face)))
                         ((not (buffer-modified-p))
                          (powerline-raw "  " unmodified-face)))
                   (cond (buffer-read-only
                          (powerline-raw (concat (char-to-string #xe0a2) " ") read-only-face 'l))
                         ((buffer-modified-p)
                          (if (not (bound-and-true-p ml-interactive?))
                              (powerline-raw (concat (char-to-string #x2621) " ") modified-face 'l)
                            (powerline-raw (concat (char-to-string #x259e) " ") unmodified-face 'l)))
                         ((not (buffer-modified-p))
                          (powerline-raw (concat (char-to-string #x26c1) " ") unmodified-face 'l)))
                   (cond (buffer-read-only
                          (funcall separator-right read-only-face filename-face))
                         ((buffer-modified-p)
                          (if (not (bound-and-true-p ml-interactive?))
                              (funcall separator-right modified-face filename-face)
                            (funcall separator-right unmodified-face filename-face)))
                         ((not (buffer-modified-p))
                          (funcall separator-right unmodified-face filename-face)))
                   ;; remote indicator
                   (when (file-remote-p default-directory)
                     (powerline-raw (concat " " (char-to-string #x211b)) remote-face))
                   ;; filename and mode info
                   (powerline-buffer-id filename-face 'l)
           (if (not (string= "-" (projectile-project-name)))
               (powerline-raw (format " [ %s ] " (projectile-project-name)) filename-face))
                   (powerline-raw " " filename-face)
                   (funcall separator-left filename-face major-mode-face)
                   ;; do not need mode info when in ansi-term
                   (unless (bound-and-true-p show-dir-in-mode-line?)
                     (powerline-major-mode major-mode-face 'l))
                   (unless (bound-and-true-p show-dir-in-mode-line?)
                     (powerline-process major-mode-face 'l))
                   ;; show a flag if in line mode in terminal
                   (when (and (bound-and-true-p show-dir-in-mode-line?) (term-in-line-mode))
                     (powerline-raw (concat (char-to-string #x2691) " Line") major-mode-face))
                   (powerline-raw " " major-mode-face)
                   ;; little trick to move the directory name to the mode line
                   ;; when inside of emacs set SHOW-DIR-IN-MODE-LINE? to enable
                   (if (bound-and-true-p show-dir-in-mode-line?)
                       (when (not (file-remote-p default-directory))
                         (powerline-raw (shorten-directory default-directory 45)
                                        shell-dir-face))
                     (powerline-minor-modes minor-mode-face 'l))
                   (unless (bound-and-true-p show-dir-in-mode-line?)
                     (dennis-powerline-narrow major-mode-face 'l)))))

        ;; concatenate it all together
        (concat (powerline-render lhs)
                (powerline-fill face1 (powerline-width rhs))
                (powerline-render rhs)))))))

      (defvar-local hidden-mode-line-mode nil)
      (define-minor-mode hidden-mode-line-mode
        "Minor mode to hide the mode-line in the current buffer."
        :init-value nil
        :global t
        :variable hidden-mode-line-mode
        :group 'editing-basics
        (if hidden-mode-line-mode
            (setq hide-mode-line mode-line-format
                  mode-line-format nil)
          (setq mode-line-format hide-mode-line
                hide-mode-line nil))
        (force-mode-line-update)
        ;; Apparently force-mode-line-update is not always enough to
        ;; redisplay the mode-line
        (redraw-display)
        (when (and (called-interactively-p 'interactive)
                   hidden-mode-line-mode)
          (run-with-idle-timer
           0 nil 'message
           (concat "Hidden Mode Line Mode enabled.  "
                   "Use M-x hidden-mode-line-mode to make the mode-line appear."))))

Formato de las columnas de númeracion

Por defecto no se activan, hay que hacerlo a mano con M-x linum-mode.

(setq linum-format "%4d \u2502 ")

Ventana limpia

Sin scroll bar, menu bar ni tool bar.

(tool-bar-mode -1)
(scroll-bar-mode -1)
(menu-bar-mode -1)

UTF-8

(prefer-coding-system       'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))

Tipo de fuente

(custom-set-faces '(default ((t (:family "DejaVu Sans Mono" :foundry "unknown" :slant normal :weight normal :height 107 :width normal)))))

Partir buffers de manera más bonita

(add-to-list 'default-frame-alist '(height . 40))
(add-to-list 'default-frame-alist '(width . 90))

Scroll

Similar a la manera de vim. No tengo claro en que se diferencia, pero me gusta cómo funciona.

(setq scroll-step            1
      scroll-conservatively  10000)

(setq scroll-margin 80
      scroll-conservatively 3000
      scroll-up-aggressively 0.02
      scroll-down-aggressively 0.02)

Aumentar y disminuir tamaño de la fuente

Con C-+ aumenta la fuente y con C-- la disminuye.

(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)

Configuración por modos o lenguajes

JSON

Los archivos cuyo nombre termine por los mencionados abajo, usarán json-mode.

(use-package json-mode
     :mode "\\.json\\'"
     :ensure t)

Haskel

Lo usé un tiempo para xmonad, pero ya no está activo.

(use-package haskell-mode
  :config
  (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  (add-hook 'haskell-mode-hook 'haskell-font-lock-symbols t)
  (put 'downcase-region 'disabled nil)
  :ensure t
  )

Markdown

Cargar markdown-mode, usar utf-8 al exportar y asociar el modo a las extensiones “.md” y “.markdown”.

(use-package markdown-mode
  :init
  :config
  (setq markdown-xhtml-header-content "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />")
  :mode "\\.md\\'"
  :ensure t)

Crear un TOC:

(use-package markdown-toc
  :ensure t
  :config
  (setq markdown-toc-header-toc-title "# Índice"))

Python

La configuración de elpy:

(defun elpy-goto-definition-or-rgrep ()
  "Go to the definition of the symbol at point, if found. Otherwise, run `elpy-rgrep-symbol'."
    (interactive)
    (ring-insert find-tag-marker-ring (point-marker))
    (condition-case nil (elpy-goto-definition)
        (error (elpy-rgrep-symbol
                   (concat "\\(def\\|class\\)\s" (thing-at-point 'symbol) "(")))))

(use-package elpy
  :ensure t
  :init
  (use-package pyvenv :ensure t)
  (setq elpy-modules '(elpy-module-sane-defaults elpy-module-company elpy-module-eldoc elpy-module-pyvenv))
  (add-hook 'python-mode-hook 'flycheck-mode)
  (setq elpy-rpc-backend "jedi")
  :config
  (add-to-list 'ivy-completing-read-handlers-alist '(elpy-doc . completing-read-default)) ;; véase https://github.com/abo-abo/swiper/issues/892
  ;; Use ipython
  (elpy-use-ipython)
  ;; Use pytest
  (setq elpy-test-runner 'elpy-test-pytest-runner)
  (setq elpy-test-pytest-runner-command '("tox"))
  (add-to-list 'elpy-project-ignored-directories "__pycache__")
  (add-to-list 'elpy-project-ignored-directories ".cache")
  (setq compilation-scroll-output 'first-error)
  (add-to-list 'auto-mode-alist '("\\.py" . python-mode))
  (add-to-list 'auto-mode-alist '("\\.py" . elpy-mode))
  (elpy-enable)
  :bind (
     ("M-." . elpy-goto-definition-or-rgrep)))

Este paquete muestra una ralla que marca los 79 carácteres, para cumplir con el pep8.

(use-package fill-column-indicator
  :init
  (setq fci-rule-color "purple")
  (setq fci-rule-column 79)
  (add-hook 'python-mode-hook 'fci-mode)
  :ensure t
  )

Corrección con flycheck, mejor que flymake:

(use-package flycheck
  :config
  (setq flycheck-global-modes '(python-mode))
  (global-flycheck-mode)
  :diminish flycheck-mode
  :ensure t
  )

web-mode

No lo he mirado mucho ya que apenas lo uso, es un copia-pega.

(defun my-setup-php ()
  (web-mode)
  (make-local-variable 'web-mode-code-indent-offset)
  (make-local-variable 'web-mode-markup-indent-offset)
  (make-local-variable 'web-mode-css-indent-offset)
  (setq web-mode-code-indent-offset 4)
  (setq web-mode-css-indent-offset 2)
  (setq web-mode-markup-indent-offset 2))

(add-to-list 'auto-mode-alist '("\\.php$" . my-setup-php))

(setq web-mode-ac-sources-alist
      '(("css" . (ac-source-words-in-buffer ac-source-css-property))
        ("php" . (ac-source-[/]words-in-buffer
                            ac-source-words-in-same-mode-buffers
                            ac-source-dictionary))))

(add-to-list 'auto-mode-alist '("\\.php$" . my-setup-php))

DockerFile

Editar archivos DockerFile.

(use-package dockerfile-mode
  :mode "Dockerfile\\'"
  :ensure t)

kivy-mode

Si el paquete no está instalado, lo instala mediante el-get.

(use-package kivy-mode
  :mode "\\.kv\\'"
  :ensure t
)

gnu-social-mode

No está activo, lo cargo de private-literate.org.

(add-to-list 'el-get-sources '(:name gnu-social-mode
                                     :description "gnu-social client"
                                     :type github
                                     :pkgname "bashrc/gnu-social-mode"))

(if (not (el-get-package-installed-p 'gnu-social-mode))
    (el-get 'sync 'gnu-social-mode)
  )

(use-package gnu-social-mode
  :load-path "el-get/gnu-social-mode/"
  :init
  (setq gnu-social-server-textlimit 140
    gnu-social-server "quitter.se"
    gnu-social-username "drymer"
    gnu-social-password "lolazing"
    gnu-social-new-dents-count 1
    gnu-social-status-format "%i %s,  %@:\n  %h%t\n\n"
    gnu-social-statuses-count 200)

  (defhydra hydra-gnu-social (:color blue :hint nil)
    "
                                                                                 ╭────────────┐
            Posts                      User                 Groups               │ GNU social │
   ╭─────────────────────────────────────────────────────────────────────────────┴────────────╯
       _k_  [_t_] Post            _p_  [_f_] Follow                  ^_J_^ Join group        [_q_] Quit
       ^↑^  [_X_] Delete post     ^↑^  [_F_] Unfollow                ^_L_^ Leave Group
       ^↓^  [_r_] Repost          ^↓^  [_i_] Profile (browser)
       _j_  [_b_] Favorite        _n_   ^ ^
       ^ ^  [_RET_] Reply         ^ ^   ^ ^
       ^ ^  [_T_] Show Conversation
   --------------------------------------------------------------------------------------------
  "
    ("C-o"        keyboard-quit "Back")
    ("q"          keyboard-quit)
    ("j"          gnu-social-goto-next-status :color red)
    ("k"          gnu-social-goto-previous-status :color red)
    ("g"          beginning-of-buffer)
    ("G"          end-of-buffer)
    ("t"          gnu-social-update-status-interactive)
    ("X"          gnu-social-delete-notice)
    ("RET"        gnu-social-reply-to-all)
    ("r"          gnu-social-repeat)
    ("u"          gnu-social-current-timeline)
    ("b"          gnu-social-favorite)
    ("f"          gnu-social-follow)
    ("F"          gnu-social-unfollow)
    ("i"          gnu-social-view-user-page)
    ("T"          gnu-social-conversation-timeline)
    ("o"          gnu-social-click)
    ("n"          gnu-social-goto-next-status-of-user :color red)
    ("p"          gnu-social-goto-previous-status-of-user :color red)
    ("a"          gnu-social-toggle-activate-buffer)
    ("J"          gnu-social-group-join)
    ("L"          gnu-social-group-leave))

  :config
  (bind-keys :map gnu-social-mode-map
         ("C-o" . hydra-gnu-social/body)
         ("q" . gnu-social-kill-buffer)
         ("Q" . gnu-social-edit-mode)
         ("j" . gnu-social-goto-next-status)
         ("k" . gnu-social-goto-previous-status)
         ("h" . gnu-social-switch-to-next-timeline)
         ("l" . gnu-social-switch-to-previous-timeline)
         ("g" . beginning-of-buffer)
         ("G" . end-of-buffer)
         ("t" . gnu-social-update-status-interactive)
         ("X" . gnu-social-delete-status)
         ("RET" . gnu-social-reply-to-all)
         ("r" . gnu-social-repeat)
         ("u" . gnu-social-current-timeline)
         ("b" . gnu-social-favorite)
         ("f" . gnu-social-follow)
         ("F" . gnu-social-unfollow)
         ("i" . gnu-social-view-user-page)
         ("T" . gnu-social-conversation-timeline)
         ("o" . gnu-social-click)
         ("n" . gnu-social-goto-next-status-of-user)
         ("p" . gnu-social-goto-previous-status-of-user)
         ("a" . gnu-social-toggle-activate-buffer)))

po-mode

(use-package po-mode
  :ensure t
  :config
  ;; Fuente: https://www.emacswiki.org/emacs/PoMode
  (defun po-wrap ()
    "Filter current po-mode buffer through `msgcat' tool to wrap all lines."
    (interactive)
    (if (eq major-mode 'po-mode)
    (let ((tmp-file (make-temp-file "po-wrap."))
          (tmp-buf (generate-new-buffer "*temp*")))
      (unwind-protect
          (progn
        (write-region (point-min) (point-max) tmp-file nil 1)
        (if (zerop
             (call-process
              "msgcat" nil tmp-buf t (shell-quote-argument tmp-file)))
            (let ((saved (point))
              (inhibit-read-only t))
              (delete-region (point-min) (point-max))
              (insert-buffer tmp-buf)
              (goto-char (min saved (point-max))))
          (with-current-buffer tmp-buf
            (error (buffer-string)))))
        (kill-buffer tmp-buf)
        (delete-file tmp-file)))))
  )

org-mode

Definir fuente de el-get

Se usa la rama maint del repositorio git. Primero se comprueba si está instalado, de no ser así se instalará. Tardará un buen rato.

;; Cutre-codigo para quitar del path el org de emacs para que no se lie al cargar de nuevo el modo
(dolist (val load-path)
  (if (string-match "lisp\/org" val)
      (delete val load-path)))
(add-to-list 'el-get-sources '(:name org-mode-maint
                     :website "http://orgmode.org/"
                     :description "Org-mode is for keeping notes, maintaining ToDo lists, doing project planning, and authoring with a fast and effective plain-text system."
                     :type git
                     :url "git://orgmode.org/org-mode.git"
                     :branch "maint"
                     :load-path ("." "lisp/")))

(if (not (el-get-package-installed-p 'org-mode-maint))
    (el-get 'sync 'org-mode-maint))

Agenda

  1. Definir archivos de la agenda

    (setq org-agenda-files '("~/Documentos/org/" "~/Documentos/BadDaemons/Articulos/articulos.org"))
    
  2. Comandos de Agenda

    (setq org-agenda-custom-commands
          '(("b" . "Blog")
        ("bi" "Idees per article" ((todo "TODO|IN-PROGRESS" ((org-agenda-files '("~/Documentos/blog/Articulos/articulos.org"))))))
        ("bp" "Articles llestos per a publicar" ((todo "READY|PROGRAMMED" ((org-agenda-files '("~/Documentos/blog/Articulos/articulos.org"))))))
        ("bc" "Articles cancel·lats" ((todo "CANCELLED" ((org-agenda-files '("~/Documentos/blog/Articulos/articulos.org"))))))
        ("bf" "Articles publicats" ((todo "DONE" ((org-agenda-files '("~/Documentos/blog/Articulos/articulos.org"))))))
        ("p" . "Projectes Personals")
        ("pp" "Projectes Personals" tags-todo "projectes")
        ("pa" "antisocial" tags-todo "antisocial")
        ("pg" "General" tags-todo "general")
        ("pi" "isso-gnusocial" tags-todo "issoGnusocial")
        ("pr" "gnusrss" tags-todo "gnusrss")
        ("pj" "jabbergram" tags-todo "jabbergram")
        ("pe" "electrumfair" tags-todo "electrumfair")
        ("pn" "nikola.el" tags-todo "nikola")
        ("v"  "Relacionat amb els VPS / chustaserver" tags-todo "vps")
        ("w" "Webs" tags "" ((org-agenda-files '("~/Documentos/org/web.org"))))))
    
  3. Capturas de notas

    (setq org-capture-templates
          '(("t" "Nota" entry (file "~/Documentos/org/notas.org")
         "* TODO %? %^G\n")))
    
  4. Definir archivo de notas para org-capture

    (setq org-default-notes-file "~/Documentos/org/notas.org")
    
  5. Estados de los objetos de las listas

    Todas las secuencias anteriores al símbolo | son tareas que no se consideran terminadas, al contrario de las que estan después de este.

    Los estados que tienen el símbolo @ son los que, al escogerlos, abren un buffer preguntando si se quiere añadir alguna nota respecto al cambio de estado. Las que tienen el símbolo !, en cambio, crean una estampa de tiempo, para dejar constancia de cuando se ha cambiado a ese estado.

    (setq org-todo-keywords
          '((sequence "TODO(t)" "NEXT(n)" "IN-PROGRESS(p@/!)" "WAITING(w@/!)" "|" "DONE(d!)" "CANCELED(c@)")))
    
  6. Refile

    Mover un arbol debajo de otro del mismo fichero o de los archivos de las agendas.

    (setq org-refile-targets '((nil :maxlevel . 10) (org-agenda-files . (:maxlevel . 4))))
    
  7. Caldav

    Lo tengo funcionando con owncloud. Si no está instalado, lo instala con el-get. Esta parte no es real, como son cosas “sensibles”, van en un fichero a parte. Pero seria algo así:

    (unless (require 'org-caldav nil 'noerror)
      (el-get-install 'org-caldav))
    
    (use-package org-caldav
      :init
      (setq org-caldav-url "http://caldav.ejemplo/")
      (setq org-caldav-calendar-id "org")
      (setq org-caldav-files '("~/Documentos/org/index.org" "~/Documentos/org/index.org_archive" "~/Documentos/org/notas.org"))
      (setq org-caldav-inbox '(id "c14f-42fe-a358-648240e73991"))
      (setq org-caldav-save-directory "~/Documentos/org/"))
    

    Esto es un workaround para un bug raro de url-cookie:

    ;; source http://emacs.stackexchange.com/questions/5469/invalid-date-01-jan-2055
    (defun url-cookie-expired-p (cookie)
      "Return non-nil if COOKIE is expired."
      (let ((exp (url-cookie-expires cookie)))
        (and (> (length exp) 0)
         (condition-case ()
             (> (float-time) (float-time (date-to-time exp)))
           (error nil)))))
    
  8. Configuración del calendario

    (setq org-icalendar-timezone "Europe/Madrid")
    
  9. calfw

    Paquete para ver las tareas de org-mode en un formato de calendario más típico. Los arrays son sólo traducciones. Si el paquete no está instalado, lo instala mediante el-get.

    (if (not (el-get-package-installed-p 'calfw))
        (el-get 'sync 'calfw))
    
    (use-package calfw
      :load-path "el-get/calfw"
      :config
      (require 'calfw-org)
      (setq cfw:org-overwrite-default-keybinding t)
      (setq calendar-week-start-day 1)
      (setq calendar-month-name-array
        ["Gener" "Febrer" "Març" "Abril" "Maig" "Juny" "Juliol" "Agost" "Septembre" "Octubre" "Novembre" "Desembre"])
      (setq calendar-day-name-array
        ["Diumenge" "Dilluns" "Dimarts" "Dimecres" "Dijous" "Divendres" "Dissabte"])
      :bind ("C-c f" . cfw:open-org-calendar))
    
  10. Tareas repetitivas

    Las tareas marcadas para repetirse, al marcarlas cómo DONE vuelven al estado TODO y añade un timestamp del dia y la hora.

    (setq org-log-repeat 'time)
    
  11. Quitar tags de la agenda

    (setq org-agenda-remove-tags t)
    

Edición, diseño y varios

  1. Atajos de teclado

    org-iswitchb muestra todos los buffers de org-mode abiertos.

    ; (define-key global-map "\C-cl" 'org-store-link)
    ; (define-key global-map "\C-ci" 'org-insert-link)
    (define-key global-map "\C-ca" 'org-agenda)
    (define-key global-map "\C-cc" 'org-capture)
    (define-key global-map "\C-cS" 'org-caldav-sync)
    
  2. Definir lenguajes que entiende babel

    (org-babel-do-load-languages
     'org-babel-load-languages
     '((dot . t)
       (emacs-lisp . t)
       (gnuplot . t)
       (latex . t)
       (ledger . t)
       (python . t)
       (shell . t)
       (sql . t)
       (sqlite . t)))
    
    (use-package yaml-mode :ensure t)
    (add-to-list 'org-src-lang-modes '("yaml" . yaml))
    (add-to-list 'org-src-lang-modes '("dockerfile" . dockerfile))
    
  3. Asteriscos bonitos

    Requerir el paquete y activarlo sólo cuando se abra un buffer de org-mode.

    (unless (require 'org-bullets nil 'noerror)
    (sleep-for 5))
      (use-package org-bullets
        :init
        (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
        :ensure t)
    
  4. Seguir links

    Presionando tanto RET cómo TAB.

    (setq org-return-follows-link t)
    (setq org-tab-follows-link t)
    
  5. Exportar Markdown

    (use-package ox-md)
    
  6. Exportar rst

    (add-to-list 'el-get-sources   '(:name ox-rst
                           :type github
                           :pkgname "masayuko/ox-rst"))
    
    (if (not (el-get-package-installed-p 'ox-rst))
        (el-get 'sync 'ox-rst))
    
    (use-package ox-rst
      :load-path "el-get/ox-rst")
    
  7. Configuracion de bloques de código

    La primera linea formatea el código cómo si se tratase de código nativo, la segunda indenta acorde al código.

    (setq org-src-fontify-natively t)
    (setq org-src-tab-acts-natively t)
    (setq org-src-preserve-indentation t)
    (setq org-edit-src-content-indentation 0)
    
  8. Elementos de marcado

    La primera línea esconde los símbolos y aplica el marcado, y la segunda cambia el color a los elementos de marcado que empiezan por =.

    (setq org-hide-emphasis-markers t)
    (add-to-list 'org-emphasis-alist '("=" (:foreground "cyan")))
    
  9. Quitar confirmación al evaluar código

    Cada vez que se evalua código de un bloque, pide que se confirme. Con el siguiente código, no lo hará.

    (setq org-confirm-babel-evaluate nil)
    
  10. Añadir imágenes in-line

    (org-display-inline-images t t)
    
  11. org2blog

    No está cargado ni configurado, lo mantengo por si acaso. Para publicar articulos con marcado org-mode en wordpress.

      (defun org2web-add-keys()
        (local-set-key "n" (quote org2blog/wp-new-entry))
        (local-set-key "p" (quote org2blog/wp-post-buffer)))
    
      (add-hook 'org2blog/wp-mode-hook 'org2web-add-keys)
    
      (require 'org2blog-autoloads)
    
    ;; habia un bug raro que hace que tengas que tener dos blogs puestos
      (setq org2blog/wp-blog-alist
            '(("blog"
               :url "http://blog.net/xmlrpc.php"
               :username "drymer"
               :default-title "Hola Mundo"
               :tags-as-categories nil)
              ("my-blog"
               :url "http://username.server.com/xmlrpc.php"
               :username "admin")))
    
      (setq org2blog/wp-use-sourcecode-shortcode nil)
    
  12. nikola

    Sirve para publicar en nikola con marcado org-mode. Las funciones cutres son mías.

    (use-package org2nikola
      :ensure t
      :init
      ;; Se instala el htmlize de melpa, el de org-mode es demasiado viejo
      (use-package htmlize :ensure t)
      :config
      (setq org2nikola-output-root-directory "/home/drymer/Documentos/BadDaemons/")
      (setq org2nikola-use-verbose-metadata t))
    
    (defun drymer/nikola-deploy-partido ()
      "Ejecuta un script que tira de at para programar el push al repositorio git."
      (interactive)
      (shell-command "/bin/bash $HOME/Documentos/BadDaemons/scripts/deploy-partido.sh &> /dev/null; echo 'Deploy programado...'"))
    
    ;; Las dos siguientes funciones probablemente no sirvan a nadie
    (defun drymer/nikola-url-post ()
      "Devuelve el enlace del articulo en el que esté el cursor."
      (interactive)
      (setq url (concat "https://daemons.it/posts/"
                        (cdr (car (org-entry-properties (point) "post_slug")))))
      (message url)
      (kill-new url))
    
    (defun drymer/nikola-url-config ()
      "Devuelve el enlace de la parte de la configuración en la que esté el cursor."
      (interactive)
      (setq url (concat "https://daemons.it/stories/mi-configuracin-de-emacs/#"
                        (cdr (car (org-entry-properties (point) "CUSTOM_ID")))))
      (message url)
      (kill-new url)))
    
    (use-package nikola
      :load-path "~/Proyectos/nikola.el/"
      :config
      (setq nikola-output-root-directory "~/Documentos/BadDaemons/")
      (setq nikola-verbose t)
      (setq nikola-webserver-auto nil)
      (setq nikola-webserver-host "127.0.0.1")
      (setq nikola-webserver-port "8080")
      (setq nikola-webserver-open-browser-p t)
      (setq nikola-deploy-input t)
      (setq nikola-deploy-input-default "Nuevo articulo")
      (setq nikola-build-before-hook-script (concat nikola-output-root-directory "scripts/pre-build.sh"))
      (setq nikola-build-after-hook-script (concat nikola-output-root-directory "scripts/post-build.sh")))
    
  13. Notas a pie de página

    Prefiero que aparezcan las notas debajo del arbol en el que se ha tomado.

    (setq org-footnote-section nil)
    
  14. toc-org

    (use-package toc-org
      :ensure t
      :init
      (add-hook 'org-mode-hook 'toc-org-enable)
      )
    
  15. Cifrar archivos

    (use-package epa-file
      :init
      (epa-file-enable)
      (setq epa-pinentry-mode 'loopback))
    ;; En el fichero ~/.gnupg/gpg-agent.conf tiene que estar:
    ;; allow-emacs-pinentry
    ;; allow-loopback-pinentry
    ;; Reiniciar con:
    ;; gpgconf --reload gpg-agent
    

    A diferencia de la función de writequit, esta establece el título como custom_id.

    ;; Fuente: https://writequit.org/articles/emacs-org-mode-generate-ids.html
    ;; requerir libreria de ayuda
    (require 'org-id)
    
    ;; función que creará los id
    (defun eos/org-custom-id-get (&optional pom create prefix)
      "Get the CUSTOM_ID property of the entry at point-or-marker POM.
       If POM is nil, refer to the entry at point. If the entry does
       not have an CUSTOM_ID, the function returns nil. However, when
       CREATE is non nil, create a CUSTOM_ID if none is present
       already. PREFIX will be passed through to `org-id-new'. In any
       case, the CUSTOM_ID of the entry is returned."
      (interactive)
      (org-with-point-at pom
        (let ((id (org-entry-get nil "CUSTOM_ID")))
          (cond
           ((and id (stringp id) (string-match "\\S-" id))
            id)
           (create
            (setq id (org-get-heading))
            (org-entry-put pom "CUSTOM_ID" id)
            (org-id-add-location id (buffer-file-name (buffer-base-buffer)))
            id)))))
    
    (defun eos/org-add-ids-to-headlines-in-file ()
      "Add CUSTOM_ID properties to all headlines in the
             current file which do not already have one."
      (interactive)
      (org-map-entries (lambda () (eos/org-custom-id-get (point) 'create))))
    
  16. Más profundidad en imenu

    (setq org-imenu-depth 9)
    
  17. Empareja simbolos de marcado y paréntesis

    (modify-syntax-entry ?/ "(/" org-mode-syntax-table)
    (modify-syntax-entry ?* "(*" org-mode-syntax-table)
    (modify-syntax-entry ?_ "(_" org-mode-syntax-table)
    (modify-syntax-entry ?= "(=" org-mode-syntax-table)
    
  18. org-protocol

    (use-package org-protocol)
    
  19. Temas para exportación en html

    (add-to-list 'el-get-sources '(:name org-html-themes
                         :type github
                         :pkgname "fniessen/org-html-themes"))
    
    (if (not (el-get-package-installed-p 'org-html-themes))
        (el-get 'sync 'org-html-themes))
    
  20. Ejecución de bloques babel asyncrona

    (add-to-list 'el-get-sources '(:name ob-async
                         :type github
                         :pkgname "astahlman/ob-async"))
    
    (if (not (el-get-package-installed-p 'ob-async))
        (el-get 'sync 'ob-async))
    
    (use-package ob-async
      :load-path "el-get/ob-async/"
      ;; :config
      ;; (add-to-list 'org-ctrl-c-ctrl-c-hook 'ob-async-org-babel-execute-src-block)
      )
    
  21. org-brain

    De momento no lo uso. Igual en el futuro.

    (add-to-list 'el-get-sources '(:name org-brain
                         :type github
                         :pkgname "Kungsgeten/org-brain"))
    
    (if (not (el-get-package-installed-p 'org-brain))
        (el-get 'sync 'org-brain))
    
    (use-package org-brain
      :load-path "el-get/org-brain"
      :config
      (setq org-brain-path "~/Documentos/org/brain/"))
    
  22. Mostrar imágenes

    (org-display-inline-images)
    

mail-mode

Para que cuadre con mutt.

(add-to-list 'auto-mode-alist '(".*mutt-" . mail-mode))

lisp

Paredit

(use-package paredit
  :ensure t)

package-lint

Comprueba fallos y convenciones.

(use-package package-lint
  :ensure t)

rainbow-delimiters

(use-package rainbow-delimiters
  :ensure t
  :config
  (add-to-list 'auto-mode-alist '("\\.el\\'" . rainbow-delimiters-mode)))

compile-mode

Varias herramientas usan el modo compile, como molecule.el o elpy:

;; Fuente: https://stackoverflow.com/questions/13397737/ansi-coloring-in-compilation-mode
(use-package compile
  :config
  (defun colorize-compilation-buffer ()
    (let ((inhibit-read-only t))
      (ansi-color-apply-on-region (point-min) (point-max))))
  (add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
  (setq compilation-scroll-output t)
  :bind (
     ("C-," . recompile)))

Funciones personalizadas

Recargar todos los buffers abiertos

Es útil cuando los archivos se suelen sincronizar y se deja el pc abierto. Los archivos que esten abiertos y hayan cambiado, se refrescaran.

(defun reload-all-buffers ()
  "Recargar todos los buffers abiertos."
  (interactive)
  (dolist (buf (buffer-list))
    (with-current-buffer buf
      (when (and (buffer-file-name) (file-exists-p (buffer-file-name)) (not (buffer-modified-p)))
        (revert-buffer t t t) )))
  (message "Refreshed open files."))

Insertar cabeceras para org-mode

(defun org-mode-insert-header (language)
  "Make a template at point."
  (interactive
   (let ((languages '("Generic" "HTML" "LaTeX" )))
     (list (ido-completing-read "To which export: " languages))
     )
   )

  (when (string= language "Generic")
    (progn
      (insert (format "#+TITLE:\n"))
      (insert (format "#+AUTHOR:\n"))
      (insert (format "#+LANGUAGE: es \n"))
      (insert (format "#+OPTIONS: toc:1\n"))
      (insert (format "#+TOC: headlines 3\n"))
      (insert (format "#+STARTUP: indent\n\n"))
      )
    )

  (when (string= language "HTML")
    (progn
      (insert (format "#+TITLE:\n"))
      (insert (format "#+AUTHOR:\n"))
      (insert (format "#+LANGUAGE: ca\n"))
      (insert (format "#+OPTIONS:   toc:1\n"))
      (insert (format "#+TOC: headlines 3\n"))
      (insert (format (concat "#+SETUPFILE: " user-emacs-directory "/css/org-html-themes/setup/theme-readtheorg.setup\n\n")))
      )
    )

  (when (string= language "LaTeX")
    (progn
      (insert (format "#+Title:\n"))
      (insert (format "#+Author:\n"))
      (insert (format "#+LANGUAGE: es\n"))
      (insert (format "#+LATEX_CLASS: article\n"))
      (insert (format "#+LATEX_CLASS_OPTIONS: [spanish,a4paper]\n"))
      (insert (format "#+LATEX_HEADER: \\usepackage{color}\n"))
      (insert (format "#+LATEX_HEADER: \\usepackage[spanish]{babel}\n\n"))

      )
    )
  )

Insertar bloque src para org-mode

Además, funciona tanto sin ninguna región activa cómo con esta. De haber región activa, la envuelve.

(defun insert-org-src-block (choice)
  "Insert src code blocks."
  (interactive
   (if (org-at-table-p)
       (call-interactively 'org-table-rotate-recalc-marks)
     (let ((choices '("emacs-lisp" "python" "shell" "css" "ledger" "latex" "lisp" "sqlite")))
       (list (ido-completing-read "Source code type: " choices)))))

  (cond
   ((region-active-p)
    (let ((start (region-beginning))
          (end (region-end)))
      (progn
        (goto-char end)
        (insert "\n#+END_SRC\n")
        (goto-char start)
        (insert (format "#+BEGIN_SRC %s\n" choice)))
      )
    )

   (t
    (insert (format "#+BEGIN_SRC %s\n" choice))
    (save-excursion (insert "\n#+END_SRC")))))

Insertar org-entities

Más información aquí.

(setq org-pretty-entities t)

(defun modi/org-entity-get-name (char)
  "Return the entity name for CHAR. For example, return \"ast\" for *."
  (let ((ll (append org-entities-user
                    org-entities))
        e name utf8)
    (catch 'break
      (while ll
        (setq e (pop ll))
        (when (not (stringp e))
          (setq utf8 (nth 6 e))
          (when (string= char utf8)
            (setq name (car e))
            (throw 'break name)))))))

(defun modi/org-insert-org-entity-maybe (orig-fun &rest args)
  "When the universal prefix C-u is used before entering any character,
insert the character's `org-entity' name if available."
  (let ((pressed-key (char-to-string (elt (this-single-command-keys) 0)))
        entity-name)
    (when (and (listp args) (eq 4 (car args)))
      (setq entity-name (modi/org-entity-get-name pressed-key))
      (when entity-name
        (setq entity-name (concat "\\" entity-name "{}"))
        (insert entity-name)
        (message (concat "Inserted `org-entity' "
                         (propertize entity-name
                                     'face 'font-lock-function-name-face)
                         " for the symbol "
                         (propertize pressed-key
                                     'face 'font-lock-function-name-face)
                         "."))))
    (when (null entity-name)
      (apply orig-fun args))))

(advice-add 'org-self-insert-command :around #'modi/org-insert-org-entity-maybe)

Añadir soporte para editar archivos en docker

Usar del siguiente modo: /docker:drunk_bardeen:/etc/passwd. Sacado de la wiki de emacs. Se puede usar el siguiente alias en bash para ver el nombre del container en ejecución:

alias dname="docker ps | perl -we 'use strict; $_ = <>; m/^(.*)NAMES/ or die; my $offset = length($1); while(<>) {substr($_, 0, $offset, q()); chomp; for(split m/\\W+/) {print qq($_:\n)} }'"

Desactivado de momento, no tengo docker en este pc.

(push
 (cons
  "docker"
  '((tramp-login-program "docker")
    (tramp-login-args (("exec" "-it") ("%h") ("/bin/bash")))
    (tramp-remote-shell "/bin/sh")
    (tramp-remote-shell-args ("-i") ("-c"))))
 tramp-methods)

(defadvice tramp-completion-handle-file-name-all-completions
    (around dotemacs-completion-docker activate)
  "(tramp-completion-handle-file-name-all-completions \"\" \"/docker:\" returns
    a list of active Docker container names, followed by colons."
  (if (equal (ad-get-arg 1) "/docker:")
      (let* ((dockernames-raw (shell-command-to-string "docker ps | perl -we 'use strict; $_ = <>; m/^(.*)NAMES/ or die; my $offset = length($1); while(<>) {substr($_, 0, $offset, q()); chomp; for(split m/\\W+/) {print qq($_:\n)} }'"))
             (dockernames (cl-remove-if-not
                           #'(lambda (dockerline) (string-match ":$" dockerline))
                           (split-string dockernames-raw "\n"))))
        (setq ad-return-value dockernames))
    ad-do-it))

Insertar fecha de hoy

(defun insert-todays-date(arg)
  (interactive "P")
  (insert (if arg (format-time-string "%d-%m-%Y")
            (format-time-string "%d-%m-%Y")
            )
          )
  )

Abrir eshell aquí

Sacada de la web Howardism.

(defun eshell-here ()
  "Opens up a new shell in the directory associated with the
current buffer's file. The eshell is renamed to match that
directory to make multiple eshell windows easier."
  (interactive)
  (let* ((parent (if (buffer-file-name)
                     (file-name-directory (buffer-file-name))
                   default-directory))
         (height (/ (window-total-height) 3))
         (name   (car (last (split-string parent "/" t)))))
    (split-window-vertically (- height))
    (other-window 1)
    (eshell "new")
    (rename-buffer (concat "*eshell: " name "*"))

    (insert (concat "ls"))
    (eshell-send-input)))

Reabrir buffer con sudo

Fuente: http://emacsredux.com/blog/2013/04/21/edit-files-as-root/ Fuente: http://stackoverflow.com/a/16408592

Es una mezcla de ambas fuentes.

(defadvice purpose-find-file-overload (after find-file-sudo activate)
  "Find file as root if necessary."
  (unless (and buffer-file-name
               (file-writable-p buffer-file-name))

    (let* ((buffer-file (buffer-file-name))
       (coincidence (string-match-p "@" buffer-file))
       (hostname)
       (buffer-name))
      (if coincidence
      (progn
        (setq hostname (substring buffer-file (+ coincidence 1)
                      (string-match-p ":" buffer-file      (+ coincidence 1))))
        (setq buffer-name
          (concat
           (substring buffer-file 0 coincidence) "@"
           (replace-regexp-in-string ":" (concat "|sudo:" hostname ":")
                         buffer-file nil nil nil (+ coincidence 1))))
        (find-alternate-file buffer-name))
      (find-alternate-file (concat "/sudo:root@localhost:" buffer-file))))))

(defadvice counsel-find-file (after find-file-sudo activate)
  "Find file as root if necessary."
  (unless (and buffer-file-name
               (file-writable-p buffer-file-name))

    (let* ((buffer-file (buffer-file-name))
       (coincidence (string-match-p "@" buffer-file))
       (hostname)
       (buffer-name))
      (if coincidence
      (progn
        (setq hostname (substring buffer-file (+ coincidence 1)
                      (string-match-p ":" buffer-file      (+ coincidence 1))))
        (setq buffer-name
          (concat
           (substring buffer-file 0 coincidence) "@"
           (replace-regexp-in-string ":" (concat "|sudo:" hostname ":")
                         buffer-file nil nil nil (+ coincidence 1))))
        (find-alternate-file buffer-name))
      (find-alternate-file (concat "/sudo:root@localhost:" buffer-file))))))

(defadvice find-file (after find-file-sudo activate)
  "Find file as root if necessary."
  (unless (and buffer-file-name
               (file-writable-p buffer-file-name))
    (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))

Antes usaba esto, ahora desactivado:

(defun sudo-edit (&optional arg)
  "Edit currently visited file as root.

With a prefix ARG prompt for a file to visit.
Will also prompt for a file to visit if current
buffer is not visiting a file."
  (interactive "P")
  (if (or arg (not buffer-file-name))
      (find-file (concat "/sudo:root@localhost:"
                         (ido-read-file-name "Find file(as root): ")))
    (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))