diff options
| author | Vinicius Jose Latorre | 2007-08-20 15:52:47 +0000 |
|---|---|---|
| committer | Vinicius Jose Latorre | 2007-08-20 15:52:47 +0000 |
| commit | 30a718e6b77f4f0c422f748dd14ea772b7fa2a1a (patch) | |
| tree | f8d95e0e73f698596d63afb25f200419254a2b12 | |
| parent | 7de61ce2d7a4600b35fb4fa5094f538aa9df2548 (diff) | |
| download | emacs-30a718e6b77f4f0c422f748dd14ea772b7fa2a1a.tar.gz emacs-30a718e6b77f4f0c422f748dd14ea772b7fa2a1a.zip | |
preceding-sexp
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 107 |
2 files changed, 61 insertions, 52 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e5390ccf057..eefd54257a4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2007-08-20 Johannes Weiner <hannes@saeurebad.de> (tiny change) | ||
| 2 | |||
| 3 | * emacs-lisp/lisp-mode.el (preceding-sexp): New fun, the code was | ||
| 4 | extracted from `eval-last-sexp-1'. | ||
| 5 | (eval-last-sexp-1): Call `preceding-sexp'. | ||
| 6 | |||
| 1 | 2007-08-19 Glenn Morris <rgm@gnu.org> | 7 | 2007-08-19 Glenn Morris <rgm@gnu.org> |
| 2 | 8 | ||
| 3 | * Makefile.in (custom-deps, finder-data, autoloads, recompile) | 9 | * Makefile.in (custom-deps, finder-data, autoloads, recompile) |
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index d41c0af3d73..8b3e5a71c61 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -537,62 +537,65 @@ If CHAR is not a character, return nil." | |||
| 537 | string)))) | 537 | string)))) |
| 538 | 538 | ||
| 539 | 539 | ||
| 540 | (defun preceding-sexp () | ||
| 541 | "Return sexp before the point." | ||
| 542 | (let ((opoint (point)) | ||
| 543 | ignore-quotes | ||
| 544 | expr) | ||
| 545 | (save-excursion | ||
| 546 | (with-syntax-table emacs-lisp-mode-syntax-table | ||
| 547 | ;; If this sexp appears to be enclosed in `...' | ||
| 548 | ;; then ignore the surrounding quotes. | ||
| 549 | (setq ignore-quotes | ||
| 550 | (or (eq (following-char) ?\') | ||
| 551 | (eq (preceding-char) ?\'))) | ||
| 552 | (forward-sexp -1) | ||
| 553 | ;; If we were after `?\e' (or similar case), | ||
| 554 | ;; use the whole thing, not just the `e'. | ||
| 555 | (when (eq (preceding-char) ?\\) | ||
| 556 | (forward-char -1) | ||
| 557 | (when (eq (preceding-char) ??) | ||
| 558 | (forward-char -1))) | ||
| 559 | |||
| 560 | ;; Skip over `#N='s. | ||
| 561 | (when (eq (preceding-char) ?=) | ||
| 562 | (let (labeled-p) | ||
| 563 | (save-excursion | ||
| 564 | (skip-chars-backward "0-9#=") | ||
| 565 | (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) | ||
| 566 | (when labeled-p | ||
| 567 | (forward-sexp -1)))) | ||
| 568 | |||
| 569 | (save-restriction | ||
| 570 | ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in | ||
| 571 | ;; `variable' so that the value is returned, not the | ||
| 572 | ;; name | ||
| 573 | (if (and ignore-quotes | ||
| 574 | (eq (following-char) ?`)) | ||
| 575 | (forward-char)) | ||
| 576 | (narrow-to-region (point-min) opoint) | ||
| 577 | (setq expr (read (current-buffer))) | ||
| 578 | ;; If it's an (interactive ...) form, it's more | ||
| 579 | ;; useful to show how an interactive call would | ||
| 580 | ;; use it. | ||
| 581 | (and (consp expr) | ||
| 582 | (eq (car expr) 'interactive) | ||
| 583 | (setq expr | ||
| 584 | (list 'call-interactively | ||
| 585 | (list 'quote | ||
| 586 | (list 'lambda | ||
| 587 | '(&rest args) | ||
| 588 | expr | ||
| 589 | 'args))))) | ||
| 590 | expr))))) | ||
| 591 | |||
| 592 | |||
| 540 | (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) | 593 | (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) |
| 541 | "Evaluate sexp before point; print value in minibuffer. | 594 | "Evaluate sexp before point; print value in minibuffer. |
| 542 | With argument, print output into current buffer." | 595 | With argument, print output into current buffer." |
| 543 | (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))) | 596 | (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))) |
| 544 | (let ((value | 597 | (eval-last-sexp-print-value (eval (preceding-sexp))))) |
| 545 | (eval (let ((stab (syntax-table)) | 598 | |
| 546 | (opoint (point)) | ||
| 547 | ignore-quotes | ||
| 548 | expr) | ||
| 549 | (save-excursion | ||
| 550 | (with-syntax-table emacs-lisp-mode-syntax-table | ||
| 551 | ;; If this sexp appears to be enclosed in `...' | ||
| 552 | ;; then ignore the surrounding quotes. | ||
| 553 | (setq ignore-quotes | ||
| 554 | (or (eq (following-char) ?\') | ||
| 555 | (eq (preceding-char) ?\'))) | ||
| 556 | (forward-sexp -1) | ||
| 557 | ;; If we were after `?\e' (or similar case), | ||
| 558 | ;; use the whole thing, not just the `e'. | ||
| 559 | (when (eq (preceding-char) ?\\) | ||
| 560 | (forward-char -1) | ||
| 561 | (when (eq (preceding-char) ??) | ||
| 562 | (forward-char -1))) | ||
| 563 | |||
| 564 | ;; Skip over `#N='s. | ||
| 565 | (when (eq (preceding-char) ?=) | ||
| 566 | (let (labeled-p) | ||
| 567 | (save-excursion | ||
| 568 | (skip-chars-backward "0-9#=") | ||
| 569 | (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) | ||
| 570 | (when labeled-p | ||
| 571 | (forward-sexp -1)))) | ||
| 572 | |||
| 573 | (save-restriction | ||
| 574 | ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in | ||
| 575 | ;; `variable' so that the value is returned, not the | ||
| 576 | ;; name | ||
| 577 | (if (and ignore-quotes | ||
| 578 | (eq (following-char) ?`)) | ||
| 579 | (forward-char)) | ||
| 580 | (narrow-to-region (point-min) opoint) | ||
| 581 | (setq expr (read (current-buffer))) | ||
| 582 | ;; If it's an (interactive ...) form, it's more | ||
| 583 | ;; useful to show how an interactive call would | ||
| 584 | ;; use it. | ||
| 585 | (and (consp expr) | ||
| 586 | (eq (car expr) 'interactive) | ||
| 587 | (setq expr | ||
| 588 | (list 'call-interactively | ||
| 589 | (list 'quote | ||
| 590 | (list 'lambda | ||
| 591 | '(&rest args) | ||
| 592 | expr | ||
| 593 | 'args))))) | ||
| 594 | expr))))))) | ||
| 595 | (eval-last-sexp-print-value value)))) | ||
| 596 | 599 | ||
| 597 | (defun eval-last-sexp-print-value (value) | 600 | (defun eval-last-sexp-print-value (value) |
| 598 | (let ((unabbreviated (let ((print-length nil) (print-level nil)) | 601 | (let ((unabbreviated (let ((print-length nil) (print-level nil)) |