comparison lisp/emacs-lisp/lisp-mode.el @ 78597:06f0300fda43

preceding-sexp
author Vinicius Jose Latorre <viniciusjl@ig.com.br>
date Mon, 20 Aug 2007 15:52:47 +0000
parents 935157c0b596
children 7191ad0f348d
comparison
equal deleted inserted replaced
78596:546a4cb2e12d 78597:06f0300fda43
535 (and string 535 (and string
536 (= (car (read-from-string string)) char) 536 (= (car (read-from-string string)) char)
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))
599 (prin1-to-string value))) 602 (prin1-to-string value)))
600 (print-length eval-expression-print-length) 603 (print-length eval-expression-print-length)