1 Star 0 Fork 2

zhengchen/emacs

forked from latpaw/emacs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
init-lisp.el 6.05 KB
一键复制 编辑 原始数据 按行查看 历史
(autoload 'turn-on-pretty-mode "pretty-mode")
;; ----------------------------------------------------------------------------
;; Paredit
;; ----------------------------------------------------------------------------
(autoload 'enable-paredit-mode "paredit")
(defun maybe-map-paredit-newline ()
(unless (or (eq major-mode 'inferior-emacs-lisp-mode) (minibufferp))
(local-set-key (kbd "RET") 'paredit-newline)))
(add-hook 'paredit-mode-hook 'maybe-map-paredit-newline)
(eval-after-load 'paredit
'(progn
(diminish 'paredit-mode " Par")
;; These are handy everywhere, not just in lisp modes
(global-set-key (kbd "M-(") 'paredit-wrap-round)
(global-set-key (kbd "M-[") 'paredit-wrap-square)
(global-set-key (kbd "M-{") 'paredit-wrap-curly)
(global-set-key (kbd "M-)") 'paredit-close-round-and-newline)
(global-set-key (kbd "M-]") 'paredit-close-square-and-newline)
(global-set-key (kbd "M-}") 'paredit-close-curly-and-newline)
(dolist (binding (list (kbd "C-<left>") (kbd "C-<right>")
(kbd "C-M-<left>") (kbd "C-M-<right>")))
(define-key paredit-mode-map binding nil))
;; Disable kill-sentence, which is easily confused with the kill-sexp
;; binding, but doesn't preserve sexp structure
(define-key paredit-mode-map [remap kill-sentence] nil)
(define-key paredit-mode-map [remap backward-kill-sentence] nil)))
;; Compatibility with other modes
(suspend-mode-during-cua-rect-selection 'paredit-mode)
;; Use paredit in the minibuffer
(add-hook 'minibuffer-setup-hook 'conditionally-enable-paredit-mode)
(defvar paredit-minibuffer-commands '(eval-expression
pp-eval-expression
eval-expression-with-eldoc
ibuffer-do-eval
ibuffer-do-view-and-eval)
"Interactive commands for which paredit should be enabled in the minibuffer.")
(defun conditionally-enable-paredit-mode ()
"Enable paredit during lisp-related minibuffer commands."
(if (memq this-command paredit-minibuffer-commands)
(enable-paredit-mode)))
;; ----------------------------------------------------------------------------
;; Hippie-expand
;; ----------------------------------------------------------------------------
(defun set-up-hippie-expand-for-elisp ()
"Locally set `hippie-expand' completion functions for use with Emacs Lisp."
(make-local-variable 'hippie-expand-try-functions-list)
(add-to-list 'hippie-expand-try-functions-list 'try-complete-lisp-symbol t)
(add-to-list 'hippie-expand-try-functions-list 'try-complete-lisp-symbol-partially t))
;; ----------------------------------------------------------------------------
;; Automatic byte compilation
;; ----------------------------------------------------------------------------
;(auto-compile-on-save-mode 1)
;; TODO: also use auto-compile-on-load-mode
;; TODO: exclude .dir-locals.el
;; ----------------------------------------------------------------------------
;; Highlight current sexp
;; ----------------------------------------------------------------------------
;; Prevent flickery behaviour due to hl-sexp-mode unhighlighting before each command
(eval-after-load 'hl-sexp
'(defadvice hl-sexp-mode (after unflicker (turn-on) activate)
(when turn-on
(remove-hook 'pre-command-hook #'hl-sexp-unhighlight))))
;; ----------------------------------------------------------------------------
;; Enable desired features for all lisp modes
;; ----------------------------------------------------------------------------
(defun sanityinc/lisp-setup ()
"Enable features useful in any Lisp mode."
(enable-paredit-mode)
(turn-on-eldoc-mode))
(defun sanityinc/emacs-lisp-setup ()
"Enable features useful when working with elisp."
(rainbow-delimiters-mode t)
(elisp-slime-nav-mode t)
(set-up-hippie-expand-for-elisp)
;; (ac-emacs-lisp-mode-setup)
(checkdoc-minor-mode))
(let* ((elispy-hooks '(emacs-lisp-mode-hook
ielm-mode-hook))
(lispy-hooks (append elispy-hooks '(lisp-mode-hook
inferior-lisp-mode-hook
lisp-interaction-mode-hook))))
(dolist (hook lispy-hooks)
(add-hook hook 'sanityinc/lisp-setup))
(dolist (hook elispy-hooks)
(add-hook hook 'sanityinc/emacs-lisp-setup)))
(require 'eldoc-eval)
(add-to-list 'auto-mode-alist '("\\.emacs-project\\'" . emacs-lisp-mode))
(add-to-list 'auto-mode-alist '("archive-contents\\'" . emacs-lisp-mode))
(define-key emacs-lisp-mode-map (kbd "C-x C-a") 'pp-macroexpand-last-sexp)
;; ----------------------------------------------------------------------------
;; Delete .elc files when reverting the .el from VC or magit
;; ----------------------------------------------------------------------------
;; When .el files are open, we can intercept when they are modified
;; by VC or magit in order to remove .elc files that are likely to
;; be out of sync.
;; This is handy while actively working on elisp files, though
;; obviously it doesn't ensure that unopened files will also have
;; their .elc counterparts removed - VC hooks would be necessary for
;; that.
(defvar sanityinc/vc-reverting nil
"Whether or not VC or Magit is currently reverting buffers.")
(defadvice revert-buffer (after sanityinc/maybe-remove-elc activate)
"If reverting from VC, delete any .elc file that will now be out of sync."
(when sanityinc/vc-reverting
(when (and (eq 'emacs-lisp-mode major-mode)
buffer-file-name
(string= "el" (file-name-extension buffer-file-name)))
(let ((elc (concat buffer-file-name "c")))
(when (file-exists-p elc)
(message "Removing out-of-sync elc file %s" (file-name-nondirectory elc))
(delete-file elc))))))
(defadvice magit-revert-buffers (around sanityinc/reverting activate)
(let ((sanityinc/vc-reverting t))
ad-do-it))
(defadvice vc-revert-buffer-internal (around sanityinc/reverting activate)
(let ((sanityinc/vc-reverting t))
ad-do-it))
(provide 'init-lisp)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cowboy13/emacs.git
git@gitee.com:cowboy13/emacs.git
cowboy13
emacs
emacs
master

搜索帮助