diff options
| author | Stefan Monnier | 2003-05-27 14:17:17 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-05-27 14:17:17 +0000 |
| commit | c689a61d1c2122988571e20db0a7af63a9650bdc (patch) | |
| tree | 107ab57718fe8a009d0cfe9a10793f64dc31cc81 | |
| parent | 61d41830c8e873e42574a07e4cbd9ba8318f843d (diff) | |
| download | emacs-c689a61d1c2122988571e20db0a7af63a9650bdc.tar.gz emacs-c689a61d1c2122988571e20db0a7af63a9650bdc.zip | |
(lisp-font-lock-syntactic-face-function): Don't infinite lop at bob.
(emacs-lisp-mode): Mark its main custom group to be `lisp'.
(prin1-char): New fun.
(eval-last-sexp-1): Use it. Use with-syntax-table as well.
(eval-defun-1): Don't replace `defvar' with `defconst'.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 138 |
1 files changed, 78 insertions, 60 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 5591d262edc..692f00b7817 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands | 1 | ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985, 1986, 1999, 2000, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985, 1986, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Maintainer: FSF | 5 | ;; Maintainer: FSF |
| 6 | ;; Keywords: lisp, languages | 6 | ;; Keywords: lisp, languages |
| @@ -146,7 +146,8 @@ | |||
| 146 | (let ((n 0)) | 146 | (let ((n 0)) |
| 147 | (goto-char (nth 8 state)) | 147 | (goto-char (nth 8 state)) |
| 148 | (condition-case nil | 148 | (condition-case nil |
| 149 | (while (progn (backward-sexp 1) (setq n (1+ n)))) | 149 | (while (and (not (bobp)) |
| 150 | (progn (backward-sexp 1) (setq n (1+ n))))) | ||
| 150 | (scan-error nil)) | 151 | (scan-error nil)) |
| 151 | (when (> n 0) | 152 | (when (> n 0) |
| 152 | (let ((sym (intern-soft | 153 | (let ((sym (intern-soft |
| @@ -320,6 +321,7 @@ if that value is non-nil." | |||
| 320 | (lisp-mode-variables) | 321 | (lisp-mode-variables) |
| 321 | (setq imenu-case-fold-search nil) | 322 | (setq imenu-case-fold-search nil) |
| 322 | (run-hooks 'emacs-lisp-mode-hook)) | 323 | (run-hooks 'emacs-lisp-mode-hook)) |
| 324 | (put 'emacs-lisp-mode 'custom-mode-group 'lisp) | ||
| 323 | 325 | ||
| 324 | (defvar lisp-mode-map | 326 | (defvar lisp-mode-map |
| 325 | (let ((map (make-sparse-keymap))) | 327 | (let ((map (make-sparse-keymap))) |
| @@ -445,6 +447,20 @@ alternative printed representations that can be displayed." | |||
| 445 | (nth 1 value)) | 447 | (nth 1 value)) |
| 446 | (goto-char (min (point-max) point))))))) | 448 | (goto-char (min (point-max) point))))))) |
| 447 | 449 | ||
| 450 | (defun prin1-char (char) | ||
| 451 | "Return a string representing CHAR as a character rather than as an integer. | ||
| 452 | If CHAR is not a character, return nil." | ||
| 453 | (and (integerp char) | ||
| 454 | (char-valid-p (event-basic-type char)) | ||
| 455 | (concat | ||
| 456 | "?" | ||
| 457 | (mapconcat | ||
| 458 | (lambda (modif) | ||
| 459 | (cond ((eq modif 'super) "\\s-") | ||
| 460 | (t (string ?\\ (upcase (aref (symbol-name modif) 0)) ?-)))) | ||
| 461 | (event-modifiers char) "") | ||
| 462 | (string (event-basic-type char))))) | ||
| 463 | |||
| 448 | (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) | 464 | (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) |
| 449 | "Evaluate sexp before point; print value in minibuffer. | 465 | "Evaluate sexp before point; print value in minibuffer. |
| 450 | With argument, print output into current buffer." | 466 | With argument, print output into current buffer." |
| @@ -454,62 +470,62 @@ With argument, print output into current buffer." | |||
| 454 | (opoint (point)) | 470 | (opoint (point)) |
| 455 | ignore-quotes | 471 | ignore-quotes |
| 456 | expr) | 472 | expr) |
| 457 | (unwind-protect | 473 | (with-syntax-table emacs-lisp-mode-syntax-table |
| 458 | (save-excursion | 474 | ;; If this sexp appears to be enclosed in `...' |
| 459 | (set-syntax-table emacs-lisp-mode-syntax-table) | 475 | ;; then ignore the surrounding quotes. |
| 460 | ;; If this sexp appears to be enclosed in `...' | 476 | (setq ignore-quotes |
| 461 | ;; then ignore the surrounding quotes. | 477 | (or (eq (following-char) ?\') |
| 462 | (setq ignore-quotes | 478 | (eq (preceding-char) ?\'))) |
| 463 | (or (eq (following-char) ?\') | 479 | (forward-sexp -1) |
| 464 | (eq (preceding-char) ?\'))) | 480 | ;; If we were after `?\e' (or similar case), |
| 465 | (forward-sexp -1) | 481 | ;; use the whole thing, not just the `e'. |
| 466 | ;; If we were after `?\e' (or similar case), | 482 | (when (eq (preceding-char) ?\\) |
| 467 | ;; use the whole thing, not just the `e'. | 483 | (forward-char -1) |
| 468 | (when (eq (preceding-char) ?\\) | 484 | (when (eq (preceding-char) ??) |
| 469 | (forward-char -1) | 485 | (forward-char -1))) |
| 470 | (when (eq (preceding-char) ??) | 486 | |
| 471 | (forward-char -1))) | 487 | ;; Skip over `#N='s. |
| 472 | 488 | (when (eq (preceding-char) ?=) | |
| 473 | ;; Skip over `#N='s. | 489 | (let (labeled-p) |
| 474 | (when (eq (preceding-char) ?=) | 490 | (save-excursion |
| 475 | (let (labeled-p) | 491 | (skip-chars-backward "0-9#=") |
| 476 | (save-excursion | 492 | (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) |
| 477 | (skip-chars-backward "0-9#=") | 493 | (when labeled-p |
| 478 | (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) | 494 | (forward-sexp -1)))) |
| 479 | (when labeled-p | 495 | |
| 480 | (forward-sexp -1)))) | 496 | (save-restriction |
| 481 | 497 | ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in | |
| 482 | (save-restriction | 498 | ;; `variable' so that the value is returned, not the |
| 483 | ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in | 499 | ;; name |
| 484 | ;; `variable' so that the value is returned, not the | 500 | (if (and ignore-quotes |
| 485 | ;; name | 501 | (eq (following-char) ?`)) |
| 486 | (if (and ignore-quotes | 502 | (forward-char)) |
| 487 | (eq (following-char) ?`)) | 503 | (narrow-to-region (point-min) opoint) |
| 488 | (forward-char)) | 504 | (setq expr (read (current-buffer))) |
| 489 | (narrow-to-region (point-min) opoint) | 505 | ;; If it's an (interactive ...) form, it's more |
| 490 | (setq expr (read (current-buffer))) | 506 | ;; useful to show how an interactive call would |
| 491 | ;; If it's an (interactive ...) form, it's more | 507 | ;; use it. |
| 492 | ;; useful to show how an interactive call would | 508 | (and (consp expr) |
| 493 | ;; use it. | 509 | (eq (car expr) 'interactive) |
| 494 | (and (consp expr) | 510 | (setq expr |
| 495 | (eq (car expr) 'interactive) | 511 | (list 'call-interactively |
| 496 | (setq expr | 512 | (list 'quote |
| 497 | (list 'call-interactively | 513 | (list 'lambda |
| 498 | (list 'quote | 514 | '(&rest args) |
| 499 | (list 'lambda | 515 | expr |
| 500 | '(&rest args) | 516 | 'args))))) |
| 501 | expr | 517 | expr)))))) |
| 502 | 'args))))) | ||
| 503 | expr)) | ||
| 504 | (set-syntax-table stab)))))) | ||
| 505 | (let ((unabbreviated (let ((print-length nil) (print-level nil)) | 518 | (let ((unabbreviated (let ((print-length nil) (print-level nil)) |
| 506 | (prin1-to-string value))) | 519 | (prin1-to-string value))) |
| 507 | (print-length eval-expression-print-length) | 520 | (print-length eval-expression-print-length) |
| 508 | (print-level eval-expression-print-level) | 521 | (print-level eval-expression-print-level) |
| 522 | (char-string (prin1-char value)) | ||
| 509 | (beg (point)) | 523 | (beg (point)) |
| 510 | end) | 524 | end) |
| 511 | (prog1 | 525 | (prog1 |
| 512 | (prin1 value) | 526 | (prin1 value) |
| 527 | (if (and (eq standard-output t) char-string) | ||
| 528 | (princ (concat " = " char-string))) | ||
| 513 | (setq end (point)) | 529 | (setq end (point)) |
| 514 | (when (and (bufferp standard-output) | 530 | (when (and (bufferp standard-output) |
| 515 | (or (not (null print-length)) | 531 | (or (not (null print-length)) |
| @@ -544,9 +560,11 @@ Likewise for other constructs as necessary." | |||
| 544 | (cond ((not (listp form)) | 560 | (cond ((not (listp form)) |
| 545 | form) | 561 | form) |
| 546 | ((and (eq (car form) 'defvar) | 562 | ((and (eq (car form) 'defvar) |
| 547 | (cdr-safe (cdr-safe form))) | 563 | (cdr-safe (cdr-safe form)) |
| 548 | ;; Force variable to be bound. | 564 | (boundp (cadr form))) |
| 549 | (cons 'defconst (cdr form))) | 565 | ;; Force variable to be re-set. |
| 566 | `(progn (defvar ,(nth 1 form) nil ,@(nthcdr 3 form)) | ||
| 567 | (setq ,(nth 1 form) ,(nth 2 form)))) | ||
| 550 | ;; `defcustom' is now macroexpanded to | 568 | ;; `defcustom' is now macroexpanded to |
| 551 | ;; `custom-declare-variable' with a quoted value arg. | 569 | ;; `custom-declare-variable' with a quoted value arg. |
| 552 | ((and (eq (car form) 'custom-declare-variable) | 570 | ((and (eq (car form) 'custom-declare-variable) |
| @@ -834,13 +852,13 @@ This function also returns nil meaning don't specify the indentation." | |||
| 834 | (progn | 852 | (progn |
| 835 | (if (not (> (save-excursion (forward-line 1) (point)) | 853 | (if (not (> (save-excursion (forward-line 1) (point)) |
| 836 | calculate-lisp-indent-last-sexp)) | 854 | calculate-lisp-indent-last-sexp)) |
| 837 | (progn (goto-char calculate-lisp-indent-last-sexp) | 855 | (progn (goto-char calculate-lisp-indent-last-sexp) |
| 838 | (beginning-of-line) | 856 | (beginning-of-line) |
| 839 | (parse-partial-sexp (point) | 857 | (parse-partial-sexp (point) |
| 840 | calculate-lisp-indent-last-sexp 0 t))) | 858 | calculate-lisp-indent-last-sexp 0 t))) |
| 841 | ;; Indent under the list or under the first sexp on the same | 859 | ;; Indent under the list or under the first sexp on the same |
| 842 | ;; line as calculate-lisp-indent-last-sexp. Note that first | 860 | ;; line as calculate-lisp-indent-last-sexp. Note that first |
| 843 | ;; thing on that line has to be complete sexp since we are | 861 | ;; thing on that line has to be complete sexp since we are |
| 844 | ;; inside the innermost containing sexp. | 862 | ;; inside the innermost containing sexp. |
| 845 | (backward-prefix-chars) | 863 | (backward-prefix-chars) |
| 846 | (current-column)) | 864 | (current-column)) |