Skip to content

Latest commit

 

History

History
145 lines (121 loc) · 5.38 KB

ome-emacs-lisp.org

File metadata and controls

145 lines (121 loc) · 5.38 KB

Oh My Emacs Lisp

This is part of oh-my-emacs.

This file contains some settings Emacs Lisp programming.

El-get packages

PackageStatusDescription
elisp-slime-navRequiredShortcuts for browsing elisp code.

Basics

This section contains some basic settings which is common to all lisp modes.

(defvar ome-lisp-modes '(emacs-lisp-mode
                         inferior-emacs-lisp-mode
                         lisp-interaction-mode
                         scheme-mode
                         lisp-mode
                         eshell-mode
                         slime-repl-mode
                         nrepl-mode
                         clojure-mode
                         common-lisp-mode)
  "List of Lisp modes.")

Emacs Lisp

Emacs is really a great “IDE” for developing Elisp programs. This section contains some goodies for elisp development.

elisp-slime-nav provide some slime-like shortcuts to find function/variable definitions, which is useful when you want to know the details, as you know, there’s no secret with source code. But the default shortcuts for elisp-slime-nav-find-elisp-thing-at-point has conflicts with evil-mode, which is enabled by default by oh-my-emacs, I still didn’t figure out a good way to solve this, so any help will be appreciated.

(defun ome-remove-elc-on-save ()
  "If you're saving an elisp file, likely the .elc is no longer valid."
  (make-local-variable 'after-save-hook)
  (add-hook 'after-save-hook
            (lambda ()
              (if (file-exists-p (concat buffer-file-name "c"))
                  (delete-file (concat buffer-file-name "c"))))))

(add-hook 'emacs-lisp-mode-hook 'ome-remove-elc-on-save)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)

(defun ome-elisp-slime-nav-setup ()
  ;; (defun ome-elisp-slime-nav-keybindings-in-evil ()
  ;;   (if (and (boundp 'evil-mode) evil-mode)
  ;;       (progn (define-key elisp-slime-nav-mode-map (kbd "C-c C-d .")
  ;;                'elisp-slime-nav-find-elisp-thing-at-point)
  ;;              (define-key elisp-slime-nav-mode-map (kbd "C-c C-d ,")
  ;;                'pop-tag-mark))))
  (dolist (hook '(emacs-lisp-mode-hook
                  lisp-interaction-mode-hook
                  ielm-mode-hook
                  eshell-mode-hook))
    (add-hook hook 'turn-on-elisp-slime-nav-mode)))
    ;; (add-hook hook 'ome-elisp-slime-nav-keybindings-in-evil)))

(ome-install 'elisp-slime-nav)

IELM

IELM is an alternative to Lisp Interactive mode, you can treat IELM as a REPL for emacs. Though convenient, IELM lacks some import features to be a real REPL, such as python-shell-send-defun in Emacs 24.3 builtin python mode.

(defun ome-visit-ielm ()
  "Switch to default `ielm' buffer.
Start `ielm' if it's not already running."
  (interactive)
  (ome-start-or-switch-to 'ielm "*ielm*"))

(define-key emacs-lisp-mode-map (kbd "C-c C-z") 'ome-visit-ielm)
(add-to-list 'ac-modes 'inferior-emacs-lisp-mode)
(add-hook 'ielm-mode-hook 'ac-emacs-lisp-mode-setup)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)

Eshell

I think you can treat Eshell as a combination of traditional Unix shell and IELM. Eshell is a command shell written in Emacs Lisp, which means it’s as portable as Emacs itself. In fact, Eshell replicates most of the features and commands from GNU CoreUtils and the Bourne-like shells, thus Eshell will function identically on any environment Emacs itself runs on.

To your surprise, Eshell does not inherit from comint-mode, which means that hooks and routines for comint-mode won’t work for Eshell. For more details about how to mastering eshell, see MASTERING ESHELL.

(add-hook 'eshell-mode-hook
          (lambda ()
            (add-to-list 'ac-sources 'ac-source-pcomplete)))

(add-to-list 'ac-modes 'eshell-mode)
(add-hook 'eshell-mode-hook 'turn-on-eldoc-mode)
(add-hook 'eshell-mode-hook 'ac-emacs-lisp-mode-setup)

Todos

  • What is overlay?
  • What is syntax?
  • Learn more knowledge about emacs key-maps, and what’s the difference between global-set-key and remap.
  • Learn more knowledge about emacs syntax-table, functions like modify-syntax-entry, etc.
  • What enable-recursive-minibuffers means to us?
  • How to do asynchronous programming in emacs lisp?
  • Make ielm as a real elisp REPL?