Skip to content

Instantly share code, notes, and snippets.

@erikmd
Last active August 20, 2021 14:13
Show Gist options
  • Save erikmd/35251ac083e7433f3e780f7eb8856782 to your computer and use it in GitHub Desktop.
Save erikmd/35251ac083e7433f3e780f7eb8856782 to your computer and use it in GitHub Desktop.
Resources for Emacs-Lisp Dev

Resources for elisp dev

How to improve emacs features discoverability & elisp debugging UX

We assume you already configured MELPA and use-package.

Otherwise, see e.g. this ~/.emacs template.

Then, add the following elisp snippet in your ~/.emacs, in order to install:

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

(use-package discover-my-major
  :ensure t
  :config
  (global-set-key (kbd "C-h C-m") #'discover-my-major)
  (global-set-key (kbd "C-h M-m") #'discover-my-mode))

;; Recall we also have the standard keybinding "C-h m".

(use-package helpful
  :ensure t
  :config
  (global-set-key (kbd "C-h f") #'helpful-callable)
  (global-set-key (kbd "C-h v") #'helpful-variable)
  (global-set-key (kbd "C-h k") #'helpful-key)
  ;;; Look up Functions (excludes macros).
  ;; (global-set-key (kbd "C-h F") #'helpful-function)
  ;;; Look up Commands (= keybindings).
  ;; (global-set-key (kbd "C-h K") #'helpful-command)
  ;;; COMMENTED-OUT as "Info-goto-emacs[-key]-command-node" are more useful.
  (add-hook 'emacs-lisp-mode-hook #'(lambda ()
    (local-set-key (kbd "C-c C-.") #'helpful-at-point))))

;; Note we can also type "C-h" after a prefix to list its expansions.

(use-package edebug-x
  :ensure t)

Finally, run M-x package-refresh-contents RET and restart Emacs.

A must-have: Magit

  • Assuming you have Git (otherwise you have to install it):
  • Setup Magit in your ~/.emacs by folllowing this Gist.

Tips and tricks to debug code

To run the debugger automatically:

  • M-: (setq debug-on-error t) RET → in case of error
  • M-: (setq debug-on-quit t) RET → when typing C-g (to debug infinite loops or so)

To cancel, replace t with nil:

  • M-: (setq debug-on-quit nil) RET.

To add a breakpoint on a function, say, learn-ocaml-mode:

  • Open the Elisp code directly or indirectly:
    • Type C-h f learn-ocaml-mode RET then TAB… and RET on learn-ocaml.el.
  • On line (def… learn-ocaml-mode, type C-x SPC.
  • Run the command at stake (in the running example: M-x learn-ocaml-mode RET).
  • You're now in edebug-mode, try typing e, i or SPC for example (or C-h m for other keybindings details).

Tutorials and further documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment