📄 lisp-mode.el
字号:
;; Lisp mode, and its idiosyncratic commands.;; Copyright (C) 1985 Free Software Foundation, Inc.;; This file is part of GNU Emacs.;; GNU Emacs is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 1, or (at your option);; any later version.;; GNU Emacs is distributed in the hope that it will be useful,;; but WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the;; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with GNU Emacs; see the file COPYING. If not, write to;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.(defvar lisp-mode-syntax-table nil "")(defvar emacs-lisp-mode-syntax-table nil "")(defvar lisp-mode-abbrev-table nil "")(if (not emacs-lisp-mode-syntax-table) (let ((i 0)) (setq emacs-lisp-mode-syntax-table (make-syntax-table)) (while (< i ?0) (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (setq i (1+ i))) (setq i (1+ ?9)) (while (< i ?A) (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (setq i (1+ i))) (setq i (1+ ?Z)) (while (< i ?a) (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (setq i (1+ i))) (setq i (1+ ?z)) (while (< i 128) (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table) (setq i (1+ i))) (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\f "> " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?. "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table) (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table)))(define-abbrev-table 'lisp-mode-abbrev-table ())(defun lisp-mode-variables (lisp-syntax) (cond (lisp-syntax (if (not lisp-mode-syntax-table) (progn (setq lisp-mode-syntax-table (copy-syntax-table emacs-lisp-mode-syntax-table)) (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table) (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table) (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table))) (set-syntax-table lisp-mode-syntax-table))) (setq local-abbrev-table lisp-mode-abbrev-table) (make-local-variable 'paragraph-start) (setq paragraph-start (concat "^$\\|" page-delimiter)) (make-local-variable 'paragraph-separate) (setq paragraph-separate paragraph-start) (make-local-variable 'paragraph-ignore-fill-prefix) (setq paragraph-ignore-fill-prefix t) (make-local-variable 'indent-line-function) (setq indent-line-function 'lisp-indent-line) (make-local-variable 'comment-start) (setq comment-start ";") (make-local-variable 'comment-start-skip) (setq comment-start-skip ";+ *") (make-local-variable 'comment-column) (setq comment-column 40) (make-local-variable 'comment-indent-hook) (setq comment-indent-hook 'lisp-comment-indent))(defun lisp-mode-commands (map) (define-key map "\e\C-q" 'indent-sexp) (define-key map "\177" 'backward-delete-char-untabify) (define-key map "\t" 'lisp-indent-line))(defvar emacs-lisp-mode-map () "")(if emacs-lisp-mode-map () (setq emacs-lisp-mode-map (make-sparse-keymap)) (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun) (lisp-mode-commands emacs-lisp-mode-map))(defun emacs-lisp-mode () "Major mode for editing Lisp code to run in Emacs.Commands:Delete converts tabs to spaces as it moves back.Blank lines separate paragraphs. Semicolons start comments.\\{emacs-lisp-mode-map}Entry to this mode calls the value of emacs-lisp-mode-hookif that value is non-nil." (interactive) (kill-all-local-variables) (use-local-map emacs-lisp-mode-map) (set-syntax-table emacs-lisp-mode-syntax-table) (setq major-mode 'emacs-lisp-mode) (setq mode-name "Emacs-Lisp") (lisp-mode-variables nil) (run-hooks 'emacs-lisp-mode-hook))(defvar lisp-mode-map ())(if lisp-mode-map () (setq lisp-mode-map (make-sparse-keymap)) (define-key lisp-mode-map "\e\C-x" 'lisp-send-defun) (define-key lisp-mode-map "\C-c\C-l" 'run-lisp) (lisp-mode-commands lisp-mode-map))(defun lisp-mode () "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.Commands:Delete converts tabs to spaces as it moves back.Blank lines separate paragraphs. Semicolons start comments.\\{lisp-mode-map}Note that `run-lisp' may be used either to start an inferior Lisp jobor to switch back to an existing one.Entry to this mode calls the value of lisp-mode-hookif that value is non-nil." (interactive) (kill-all-local-variables) (use-local-map lisp-mode-map) (setq major-mode 'lisp-mode) (setq mode-name "Lisp") (lisp-mode-variables t) (set-syntax-table lisp-mode-syntax-table) (run-hooks 'lisp-mode-hook));; This will do unless shell.el is loaded.(defun lisp-send-defun nil "Send the current defun to the Lisp process made by M-x run-lisp." (interactive) (error "Process lisp does not exist"))(defvar lisp-interaction-mode-map ())(if lisp-interaction-mode-map () (setq lisp-interaction-mode-map (make-sparse-keymap)) (lisp-mode-commands lisp-interaction-mode-map) (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun) (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))(defun lisp-interaction-mode () "Major mode for typing and evaluating Lisp forms.Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expressionbefore point, and prints its value into the buffer, advancing point.Commands:Delete converts tabs to spaces as it moves back.Paragraphs are separated only by blank lines. Semicolons start comments.\\{lisp-interaction-mode-map}Entry to this mode calls the value of lisp-interaction-mode-hookif that value is non-nil." (interactive) (kill-all-local-variables) (use-local-map lisp-interaction-mode-map) (set-syntax-table emacs-lisp-mode-syntax-table) (setq major-mode 'lisp-interaction-mode) (setq mode-name "Lisp Interaction") (lisp-mode-variables nil) (run-hooks 'lisp-interaction-mode-hook))(defun eval-print-last-sexp (arg) "Evaluate sexp before point; print value into current buffer." (interactive "P") (eval-region (let ((stab (syntax-table))) (unwind-protect (save-excursion (set-syntax-table emacs-lisp-mode-syntax-table) (forward-sexp -1) (point)) (set-syntax-table stab))) (point) (current-buffer)))(defun eval-last-sexp (arg) "Evaluate sexp before point; print value in minibuffer.With argument, print output into current buffer." (interactive "P") (eval-region (let ((stab (syntax-table))) (unwind-protect (save-excursion (set-syntax-table emacs-lisp-mode-syntax-table) (forward-sexp -1) (point)) (set-syntax-table stab))) (point) (if arg (current-buffer) t)))(defun eval-defun (arg) "Evaluate defun that point is in or before.Print value in minibuffer.With argument, insert value in current buffer after the defun." (interactive "P") (save-excursion (end-of-defun) (let ((end (point))) (beginning-of-defun) (eval-region (point) end (if arg (current-buffer) t)))))(defun lisp-comment-indent () (if (looking-at ";;;") (current-column) (if (looking-at ";;") (let ((tem (calculate-lisp-indent))) (if (listp tem) (car tem) tem)) (skip-chars-backward " \t") (max (if (bolp) 0 (1+ (current-column))) comment-column))))(defconst lisp-indent-offset nil "")(defconst lisp-indent-hook 'lisp-indent-hook "")(defun lisp-indent-line (&optional whole-exp) "Indent current line as Lisp code.With argument, indent any additional lines of the same expressionrigidly along with this one." (interactive "P") (let ((indent (calculate-lisp-indent)) shift-amt beg end (pos (- (point-max) (point)))) (beginning-of-line) (setq beg (point)) (skip-chars-forward " \t") (if (looking-at ";;;") ;; Don't alter indentation of a ;;; comment line. nil (if (and (looking-at ";") (not (looking-at ";;"))) ;; Single-semicolon comment lines should be indented ;; as comment lines, not as code. (progn (indent-for-comment) (forward-char -1)) (if (listp indent) (setq indent (car indent))) (setq shift-amt (- indent (current-column))) (if (zerop shift-amt) nil (delete-region beg (point)) (indent-to indent))) ;; If initial point was within line's indentation, ;; position after the indentation. Else stay at same point in text. (if (> (- (point-max) pos) (point)) (goto-char (- (point-max) pos))) ;; If desired, shift remaining lines of expression the same amount. (and whole-exp (not (zerop shift-amt)) (save-excursion (goto-char beg) (forward-sexp 1) (setq end (point)) (goto-char beg) (forward-line 1) (setq beg (point)) (> end beg)) (indent-code-rigidly beg end shift-amt)))))(defun calculate-lisp-indent (&optional parse-start) "Return appropriate indentation for current line as Lisp code.In usual case returns an integer: the column to indent to.Can instead return a list, whose car is the column to indent to.This means that following lines at the same level of indentationshould not necessarily be indented the same way.The second element of the list is the buffer positionof the start of the containing expression." (save-excursion (beginning-of-line) (let ((indent-point (point)) state paren-depth ;; setting this to a number inhibits calling hook (desired-indent nil) (retry t)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -