Table of Contents


Code snippets


  • Disable Meta behaviour in Emacs for right Option key

    Rif.: apple.stackexchange.com

    (when (eq system-type 'darwin)
      (setq mac-right-option-modifier 'none))
  • Generic function to get JSON data from a URI
    (require 'json)
    (defun get-json-data (url)
          (url-retrieve-synchronously url)
        (goto-char (+ 1 url-http-end-of-headers))
  • Org 2 Webjump list

    Convert a list of bookmarks (expressend in a org document) in a data structure suitable for webjump.

    (require 'cl)
    (defun get-webjump-sites ()
      "converts a org document in a data structure suitable for webjump"
      (let ((regex "\\[\\[\\(.*\\)\\]\\[\\(.*\\)\\]\\]"))
        (with-current-buffer (get-file-buffer "~/Dropbox/stefanorodighiero.net/links.org")
          (loop for i in (org-map-entries 'org-entry-properties nil 'file)
                for item-string = (cdr (assoc "ITEM" i))
                if (string-match regex item-string)
                collect `(,(match-string 2 item-string) . ,(match-string 1 item-string))))))


Download the image under the cursor

(defun shr-download-image ()
  "Downloads the image under point"
  (let ((url (get-text-property (point) 'image-url)))
    (if (not url)
        (message "No image under point!")
      (url-copy-file url (expand-file-name (url-file-nondirectory url)

(define-key elfeed-show-mode-map "D" #'shr-download-image)


An example of a custom-made Helm menu based on current buffer contents

(defun helm-subroutines ()
  (helm :sources '(((name . "Perl subroutines")
                    (headline "^sub ")))))

Switch theme

Disables all enabled themes before activating the new one:

(defun switch-theme (theme)
    (intern (completing-read "Switch to custom theme: "
                             (mapcar 'symbol-name
  (dolist (curr custom-enabled-themes) (disable-theme curr))
  (load-theme theme))

Create thumbnail

(defun create-thumbnail (filename)
  (let* ((dir (file-name-directory filename))
         (basename (file-name-base filename))
         (extension (downcase (file-name-extension filename)))
         (thumb-filename (concat dir basename "-thumb." extension)))
    (call-process "convert" nil nil nil
                  "-resize" "25%"

Clone indirect buffer in another frame

Rif.: Superuser

(global-set-key [?\C-x ?5 ?c]
  '(lambda(newname display-flag)
    "Like `clone-indirect-buffer-other-window' but display in another frame."
        (if (get major-mode 'no-clone-indirect)
          (error "Cannot indirectly clone a buffer in %s mode" mode-name))
        (list (if current-prefix-arg
          (read-buffer "Name of indirect buffer: " (current-buffer))) t)))
      (let ((newbuf (clone-indirect-buffer newname display-flag)))
      (switch-to-buffer-other-frame newbuf)))))


Rif.: Emacswiki

(setq dired-dwim-target t)

Keys and commands


Key sequence Command Elisp function
C-x r t Rectagle: prefix  
C-c C-x C-v Toggle inline image mode  
M-g M-g Goto line…  
C-u C-x C-e Eval and insert output at point  
M-0 C-k Kill and yank backwards  
C-s C-w Appends the rest of the word under the cursor to the search pattern  


Key sequence Command Elisp function
+ Create directory  
m/u Mark/Unmark for deletion  
C-c C-q Edit mode  
C-c C-c (in edit mode) Apply changes  
C-c C-k (in edit mode) Cancel  
# Flag all auto-save files (files whose names start and end with ‘#’) for deletion  
~ Flag all backup files (files whose names end with ‘~’) for deletion  
% & Flag for deletion all files with certain kinds of names which suggest you could easily create those files again.  


Key sequence Command Elisp function
C-c c Capture  
C-c C-w Refile (org-refile)
C-c C-t Toggle state  
C-c C-d Add deadline  
C-c / Sparse tree (org-sparse-tree)
C-c C-x b Show the current subtree in an indirect buffer (org-tree-to-indirect-buffer)

Markdown mode

Key sequence Command Elisp function
C-c C-s b Insert blockquote (markdown-insert-blockquote)
C-c C-c p Preview  


Key sequence Command Elisp function
H Show browsing history  
l   (eww-back-url)
w Copy current page URL (eww-copy-page-url)


Key sequence Command Elisp function
C-x c C-x C-f   (helm-find-files)


Key bindings

Key sequence Command Elisp function
C-M-i Complete symbol  
C-M-x Evaluate the current toplevel form slime-eval-defun
<Leader> !p Change package  

<Leader> is comma (,).


This comes from #lisp IRC channel: "when you are in a slime repl window, slime-process will return that instance process", so

(switch-to-buffer (process-buffer

Date: 2014-04-26 sab 00:00

Author: Stefano Rodighiero

Created: 2017-01-29 dom 11:47