diff options
| author | Vinicius Jose Latorre | 2007-08-20 15:53:09 +0000 |
|---|---|---|
| committer | Vinicius Jose Latorre | 2007-08-20 15:53:09 +0000 |
| commit | 88b73bbf7e73d387813605b92a442c62192304cb (patch) | |
| tree | b4c3f98f0d4e59f39e42c08e936e7834dc7f577b | |
| parent | 1c0f367bc2a22999b15b8a66bb672ef580bb1b32 (diff) | |
| download | emacs-88b73bbf7e73d387813605b92a442c62192304cb.tar.gz emacs-88b73bbf7e73d387813605b92a442c62192304cb.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 cf3635964aa..a8942955942 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-20 Thien-Thi Nguyen <ttn@gnuvola.org> | 7 | 2007-08-20 Thien-Thi Nguyen <ttn@gnuvola.org> |
| 2 | 8 | ||
| 3 | * vc-rcs.el (vc-rcs-annotate-command): | 9 | * vc-rcs.el (vc-rcs-annotate-command): |
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 655677998e0..b6f6a450791 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -539,62 +539,65 @@ If CHAR is not a character, return nil." | |||
| 539 | string)))) | 539 | string)))) |
| 540 | 540 | ||
| 541 | 541 | ||
| 542 | (defun preceding-sexp () | ||
| 543 | "Return sexp before the point." | ||
| 544 | (let ((opoint (point)) | ||
| 545 | ignore-quotes | ||
| 546 | expr) | ||
| 547 | (save-excursion | ||
| 548 | (with-syntax-table emacs-lisp-mode-syntax-table | ||
| 549 | ;; If this sexp appears to be enclosed in `...' | ||
| 550 | ;; then ignore the surrounding quotes. | ||
| 551 | (setq ignore-quotes | ||
| 552 | (or (eq (following-char) ?\') | ||
| 553 | (eq (preceding-char) ?\'))) | ||
| 554 | (forward-sexp -1) | ||
| 555 | ;; If we were after `?\e' (or similar case), | ||
| 556 | ;; use the whole thing, not just the `e'. | ||
| 557 | (when (eq (preceding-char) ?\\) | ||
| 558 | (forward-char -1) | ||
| 559 | (when (eq (preceding-char) ??) | ||
| 560 | (forward-char -1))) | ||
| 561 | |||
| 562 | ;; Skip over `#N='s. | ||
| 563 | (when (eq (preceding-char) ?=) | ||
| 564 | (let (labeled-p) | ||
| 565 | (save-excursion | ||
| 566 | (skip-chars-backward "0-9#=") | ||
| 567 | (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) | ||
| 568 | (when labeled-p | ||
| 569 | (forward-sexp -1)))) | ||
| 570 | |||
| 571 | (save-restriction | ||
| 572 | ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in | ||
| 573 | ;; `variable' so that the value is returned, not the | ||
| 574 | ;; name | ||
| 575 | (if (and ignore-quotes | ||
| 576 | (eq (following-char) ?`)) | ||
| 577 | (forward-char)) | ||
| 578 | (narrow-to-region (point-min) opoint) | ||
| 579 | (setq expr (read (current-buffer))) | ||
| 580 | ;; If it's an (interactive ...) form, it's more | ||
| 581 | ;; useful to show how an interactive call would | ||
| 582 | ;; use it. | ||
| 583 | (and (consp expr) | ||
| 584 | (eq (car expr) 'interactive) | ||
| 585 | (setq expr | ||
| 586 | (list 'call-interactively | ||
| 587 | (list 'quote | ||
| 588 | (list 'lambda | ||
| 589 | '(&rest args) | ||
| 590 | expr | ||
| 591 | 'args))))) | ||
| 592 | expr))))) | ||
| 593 | |||
| 594 | |||
| 542 | (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) | 595 | (defun eval-last-sexp-1 (eval-last-sexp-arg-internal) |
| 543 | "Evaluate sexp before point; print value in minibuffer. | 596 | "Evaluate sexp before point; print value in minibuffer. |
| 544 | With argument, print output into current buffer." | 597 | With argument, print output into current buffer." |
| 545 | (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))) | 598 | (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))) |
| 546 | (let ((value | 599 | (eval-last-sexp-print-value (eval (preceding-sexp))))) |
| 547 | (eval (let ((stab (syntax-table)) | 600 | |
| 548 | (opoint (point)) | ||
| 549 | ignore-quotes | ||
| 550 | expr) | ||
| 551 | (save-excursion | ||
| 552 | (with-syntax-table emacs-lisp-mode-syntax-table | ||
| 553 | ;; If this sexp appears to be enclosed in `...' | ||
| 554 | ;; then ignore the surrounding quotes. | ||
| 555 | (setq ignore-quotes | ||
| 556 | (or (eq (following-char) ?\') | ||
| 557 | (eq (preceding-char) ?\'))) | ||
| 558 | (forward-sexp -1) | ||
| 559 | ;; If we were after `?\e' (or similar case), | ||
| 560 | ;; use the whole thing, not just the `e'. | ||
| 561 | (when (eq (preceding-char) ?\\) | ||
| 562 | (forward-char -1) | ||
| 563 | (when (eq (preceding-char) ??) | ||
| 564 | (forward-char -1))) | ||
| 565 | |||
| 566 | ;; Skip over `#N='s. | ||
| 567 | (when (eq (preceding-char) ?=) | ||
| 568 | (let (labeled-p) | ||
| 569 | (save-excursion | ||
| 570 | (skip-chars-backward "0-9#=") | ||
| 571 | (setq labeled-p (looking-at "\\(#[0-9]+=\\)+"))) | ||
| 572 | (when labeled-p | ||
| 573 | (forward-sexp -1)))) | ||
| 574 | |||
| 575 | (save-restriction | ||
| 576 | ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in | ||
| 577 | ;; `variable' so that the value is returned, not the | ||
| 578 | ;; name | ||
| 579 | (if (and ignore-quotes | ||
| 580 | (eq (following-char) ?`)) | ||
| 581 | (forward-char)) | ||
| 582 | (narrow-to-region (point-min) opoint) | ||
| 583 | (setq expr (read (current-buffer))) | ||
| 584 | ;; If it's an (interactive ...) form, it's more | ||
| 585 | ;; useful to show how an interactive call would | ||
| 586 | ;; use it. | ||
| 587 | (and (consp expr) | ||
| 588 | (eq (car expr) 'interactive) | ||
| 589 | (setq expr | ||
| 590 | (list 'call-interactively | ||
| 591 | (list 'quote | ||
| 592 | (list 'lambda | ||
| 593 | '(&rest args) | ||
| 594 | expr | ||
| 595 | 'args))))) | ||
| 596 | expr))))))) | ||
| 597 | (eval-last-sexp-print-value value)))) | ||
| 598 | 601 | ||
| 599 | (defun eval-last-sexp-print-value (value) | 602 | (defun eval-last-sexp-print-value (value) |
| 600 | (let ((unabbreviated (let ((print-length nil) (print-level nil)) | 603 | (let ((unabbreviated (let ((print-length nil) (print-level nil)) |