0%

Learn Elisp The Hard Way -- 06.Elisp Files

Elisp in Files

介绍

~/.emacs.d/.omars-dir/下编辑文件myomar.el

(defun omar-hip ()
(interactive)
(message "hip, hop, don't stop"))
(defun omar-hotel ()
(interactive)
(message "hotel, motel, holiday inn"))

为了让文件生效,我们需要在init.el添加路径:

(add-to-list 'load-path "~/.emacs.d/omars-dir")

使用文件

init.el文件的load-path后面添加:

(require 'myomar)

在文件myomar.el文件尾部添加:

(provide 'myomar)

执行模式

Working with Buffers

准备我们的Elisp文件omarmenu.el:

(defun omar-count ()
(interactive)
(message "When we have finished this will count the number of words in the current buffer"))

(defvar menu-bar-omar-menu (make-sparse-keymap "Omar"))

(define-key-after global-map [menu-bar omar]
(cons "Omar's Menu" (make-sparse-keymap "Omar")))

(define-key global-map [menu-bar omar omar-count]
'(menu-item "Count" omar-count
:help "Will eventually count words in the current buffer!"))

(global-set-key (kbd "C-c a") 'omar-count)

init.el添加:

(require 'omarmenu)

Scope Of Variables

set, setq, let, let*, etc

介绍

Elisp有四中范围

  • global scope
  • local scope
  • buffer-local scope
  • terminal-local scope