aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu2013-06-12 10:37:38 +0800
committerLeo Liu2013-06-12 10:37:38 +0800
commitdaabf15ad87707e788810b1c780ff3a31bb757b4 (patch)
tree089879f0ef42c884d5431dd974b58b85d5de379a
parentcf4e5178a3e00bd5d46fc609b6591af7ae19833f (diff)
downloademacs-daabf15ad87707e788810b1c780ff3a31bb757b4.tar.gz
emacs-daabf15ad87707e788810b1c780ff3a31bb757b4.zip
* progmodes/octave.el (inferior-octave-startup)
(inferior-octave-completion-table) (inferior-octave-track-window-width-change) (octave-eldoc-function-signatures, octave-help) (octave-find-definition): Use single quoted strings. (inferior-octave-startup-args): Change default value. (inferior-octave-startup): Do not hard code "-i" and "--no-line-editing". (inferior-octave-resync-dirs): Add optional arg NOERROR. (inferior-octave-directory-tracker): Use it. (octave-goto-function-definition): Robustify. (octave-help): Support highlighting operators in 'See also'. (octave-find-definition): Find subfunctions only in Octave mode.
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/progmodes/octave.el74
2 files changed, 56 insertions, 34 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f3ea1419873..50eb27472d5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12013-06-12 Leo Liu <sdl.web@gmail.com>
2
3 * progmodes/octave.el (inferior-octave-startup)
4 (inferior-octave-completion-table)
5 (inferior-octave-track-window-width-change)
6 (octave-eldoc-function-signatures, octave-help)
7 (octave-find-definition): Use single quoted strings.
8 (inferior-octave-startup-args): Change default value.
9 (inferior-octave-startup): Do not hard code "-i" and
10 "--no-line-editing".
11 (inferior-octave-resync-dirs): Add optional arg NOERROR.
12 (inferior-octave-directory-tracker): Use it.
13 (octave-goto-function-definition): Robustify.
14 (octave-help): Support highlighting operators in 'See also'.
15 (octave-find-definition): Find subfunctions only in Octave mode.
16
12013-06-12 Stefan Monnier <monnier@iro.umontreal.ca> 172013-06-12 Stefan Monnier <monnier@iro.umontreal.ca>
2 18
3 * help-fns.el (help-fns--compiler-macro): If the handler function is 19 * help-fns.el (help-fns--compiler-macro): If the handler function is
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index aaf723f8a8b..12b360792ab 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -608,12 +608,13 @@ startup."
608 :group 'octave 608 :group 'octave
609 :version "24.4") 609 :version "24.4")
610 610
611(defcustom inferior-octave-startup-args nil 611(defcustom inferior-octave-startup-args '("-i" "--no-line-editing")
612 "List of command line arguments for the inferior Octave process. 612 "List of command line arguments for the inferior Octave process.
613For example, for suppressing the startup message and using `traditional' 613For example, for suppressing the startup message and using `traditional'
614mode, set this to (\"-q\" \"--traditional\")." 614mode, include \"-q\" and \"--traditional\"."
615 :type '(repeat string) 615 :type '(repeat string)
616 :group 'octave) 616 :group 'octave
617 :version "24.4")
617 618
618(defcustom inferior-octave-mode-hook nil 619(defcustom inferior-octave-mode-hook nil
619 "Hook to be run when Inferior Octave mode is started." 620 "Hook to be run when Inferior Octave mode is started."
@@ -723,13 +724,13 @@ startup file, `~/.emacs-octave'."
723 (substring inferior-octave-buffer 1 -1) 724 (substring inferior-octave-buffer 1 -1)
724 inferior-octave-buffer 725 inferior-octave-buffer
725 inferior-octave-program 726 inferior-octave-program
726 (append (list "-i" "--no-line-editing") 727 (append
727 ;; --no-gui is introduced in Octave > 3.7 728 inferior-octave-startup-args
728 (when (zerop (process-file inferior-octave-program 729 ;; --no-gui is introduced in Octave > 3.7
729 nil nil nil 730 (and (not (member "--no-gui" inferior-octave-startup-args))
730 "--no-gui" "--help")) 731 (zerop (process-file inferior-octave-program
731 (list "--no-gui")) 732 nil nil nil "--no-gui" "--help"))
732 inferior-octave-startup-args)))) 733 '("--no-gui"))))))
733 (set-process-filter proc 'inferior-octave-output-digest) 734 (set-process-filter proc 'inferior-octave-output-digest)
734 (setq inferior-octave-process proc 735 (setq inferior-octave-process proc
735 inferior-octave-output-list nil 736 inferior-octave-output-list nil
@@ -759,10 +760,10 @@ startup file, `~/.emacs-octave'."
759 (inferior-octave-send-list-and-digest (list "PS2\n")) 760 (inferior-octave-send-list-and-digest (list "PS2\n"))
760 (when (string-match "\\(PS2\\|ans\\) = *$" 761 (when (string-match "\\(PS2\\|ans\\) = *$"
761 (car inferior-octave-output-list)) 762 (car inferior-octave-output-list))
762 (inferior-octave-send-list-and-digest (list "PS2 (\"> \");\n"))) 763 (inferior-octave-send-list-and-digest (list "PS2 ('> ');\n")))
763 764
764 (inferior-octave-send-list-and-digest 765 (inferior-octave-send-list-and-digest
765 (list "disp(getenv(\"OCTAVE_SRCDIR\"))\n")) 766 (list "disp (getenv ('OCTAVE_SRCDIR'))\n"))
766 (process-put proc 'octave-srcdir 767 (process-put proc 'octave-srcdir
767 (unless (equal (car inferior-octave-output-list) "") 768 (unless (equal (car inferior-octave-output-list) "")
768 (car inferior-octave-output-list))) 769 (car inferior-octave-output-list)))
@@ -771,19 +772,19 @@ startup file, `~/.emacs-octave'."
771 (inferior-octave-send-list-and-digest 772 (inferior-octave-send-list-and-digest
772 (list "more off;\n" 773 (list "more off;\n"
773 (unless (equal inferior-octave-output-string ">> ") 774 (unless (equal inferior-octave-output-string ">> ")
774 "PS1 (\"\\\\s> \");\n") 775 "PS1 ('\\\\s> ');\n")
775 (when (and inferior-octave-startup-file 776 (when (and inferior-octave-startup-file
776 (file-exists-p inferior-octave-startup-file)) 777 (file-exists-p inferior-octave-startup-file))
777 (format "source (\"%s\");\n" inferior-octave-startup-file)))) 778 (format "source ('%s');\n" inferior-octave-startup-file))))
778 (when inferior-octave-output-list 779 (when inferior-octave-output-list
779 (insert-before-markers 780 (insert-before-markers
780 (mapconcat 'identity inferior-octave-output-list "\n"))) 781 (mapconcat 'identity inferior-octave-output-list "\n")))
781 782
782 ;; And finally, everything is back to normal. 783 ;; And finally, everything is back to normal.
783 (set-process-filter proc 'comint-output-filter) 784 (set-process-filter proc 'comint-output-filter)
784 ;; Just in case, to be sure a cd in the startup file 785 ;; Just in case, to be sure a cd in the startup file won't have
785 ;; won't have detrimental effects. 786 ;; detrimental effects.
786 (inferior-octave-resync-dirs) 787 (with-demoted-errors (inferior-octave-resync-dirs))
787 ;; Generate a proper prompt, which is critical to 788 ;; Generate a proper prompt, which is critical to
788 ;; `comint-history-isearch-backward-regexp'. Bug#14433. 789 ;; `comint-history-isearch-backward-regexp'. Bug#14433.
789 (comint-send-string proc "\n"))) 790 (comint-send-string proc "\n")))
@@ -799,7 +800,7 @@ startup file, `~/.emacs-octave'."
799 (unless (and (equal (car cache) command) 800 (unless (and (equal (car cache) command)
800 (< (float-time) (+ 5 (cadr cache)))) 801 (< (float-time) (+ 5 (cadr cache))))
801 (inferior-octave-send-list-and-digest 802 (inferior-octave-send-list-and-digest
802 (list (concat "completion_matches (\"" command "\");\n"))) 803 (list (format "completion_matches ('%s');\n" command)))
803 (setq cache (list command (float-time) 804 (setq cache (list command (float-time)
804 (delete-consecutive-dups 805 (delete-consecutive-dups
805 (sort inferior-octave-output-list 'string-lessp))))) 806 (sort inferior-octave-output-list 'string-lessp)))))
@@ -898,8 +899,8 @@ output is passed to the filter `inferior-octave-output-digest'."
898 "Tracks `cd' commands issued to the inferior Octave process. 899 "Tracks `cd' commands issued to the inferior Octave process.
899Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused." 900Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused."
900 (when inferior-octave-directory-tracker-resync 901 (when inferior-octave-directory-tracker-resync
901 (setq inferior-octave-directory-tracker-resync nil) 902 (or (inferior-octave-resync-dirs 'noerror)
902 (inferior-octave-resync-dirs)) 903 (setq inferior-octave-directory-tracker-resync nil)))
903 (cond 904 (cond
904 ((string-match "^[ \t]*cd[ \t;]*$" string) 905 ((string-match "^[ \t]*cd[ \t;]*$" string)
905 (cd "~")) 906 (cd "~"))
@@ -911,13 +912,17 @@ Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused."
911 (error-message-string err) 912 (error-message-string err)
912 (match-string 1 string))))))) 913 (match-string 1 string)))))))
913 914
914(defun inferior-octave-resync-dirs () 915(defun inferior-octave-resync-dirs (&optional noerror)
915 "Resync the buffer's idea of the current directory. 916 "Resync the buffer's idea of the current directory.
916This command queries the inferior Octave process about its current 917This command queries the inferior Octave process about its current
917directory and makes this the current buffer's default directory." 918directory and makes this the current buffer's default directory."
918 (interactive) 919 (interactive)
919 (inferior-octave-send-list-and-digest '("disp (pwd ())\n")) 920 (inferior-octave-send-list-and-digest '("disp (pwd ())\n"))
920 (cd (car inferior-octave-output-list))) 921 (condition-case err
922 (progn
923 (cd (car inferior-octave-output-list))
924 t)
925 (error (unless noerror (signal (car err) (cdr err))))))
921 926
922(defcustom inferior-octave-minimal-columns 80 927(defcustom inferior-octave-minimal-columns 80
923 "The minimal column width for the inferior Octave process." 928 "The minimal column width for the inferior Octave process."
@@ -935,7 +940,7 @@ directory and makes this the current buffer's default directory."
935 (when (and inferior-octave-process 940 (when (and inferior-octave-process
936 (process-live-p inferior-octave-process)) 941 (process-live-p inferior-octave-process))
937 (inferior-octave-send-list-and-digest 942 (inferior-octave-send-list-and-digest
938 (list (format "putenv(\"COLUMNS\", \"%s\");\n" width))))))) 943 (list (format "putenv ('COLUMNS', '%s');\n" width)))))))
939 944
940 945
941;;; Miscellaneous useful functions 946;;; Miscellaneous useful functions
@@ -989,7 +994,7 @@ directory and makes this the current buffer's default directory."
989 (setq found t))) 994 (setq found t)))
990 (unless found (goto-char orig)) 995 (unless found (goto-char orig))
991 found)))) 996 found))))
992 (pcase (file-name-extension (buffer-file-name)) 997 (pcase (and buffer-file-name (file-name-extension buffer-file-name))
993 (`"cc" (funcall search 998 (`"cc" (funcall search
994 "\\_<DEFUN\\(?:_DLD\\)?\\s-*(\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)" 1)) 999 "\\_<DEFUN\\(?:_DLD\\)?\\s-*(\\s-*\\(\\(?:\\sw\\|\\s_\\)+\\)" 1))
995 (t (funcall search octave-function-header-regexp 3))))) 1000 (t (funcall search octave-function-header-regexp 3)))))
@@ -1519,9 +1524,7 @@ code line."
1519(defun octave-eldoc-function-signatures (fn) 1524(defun octave-eldoc-function-signatures (fn)
1520 (unless (equal fn (car octave-eldoc-cache)) 1525 (unless (equal fn (car octave-eldoc-cache))
1521 (inferior-octave-send-list-and-digest 1526 (inferior-octave-send-list-and-digest
1522 (list (format "\ 1527 (list (format "print_usage ('%s');\n" fn)))
1523if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n"
1524 fn fn)))
1525 (let (result) 1528 (let (result)
1526 (dolist (line inferior-octave-output-list) 1529 (dolist (line inferior-octave-output-list)
1527 (when (string-match 1530 (when (string-match
@@ -1622,7 +1625,7 @@ if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n"
1622 "Display the documentation of FN." 1625 "Display the documentation of FN."
1623 (interactive (list (octave-completing-read))) 1626 (interactive (list (octave-completing-read)))
1624 (inferior-octave-send-list-and-digest 1627 (inferior-octave-send-list-and-digest
1625 (list (format "help \"%s\"\n" fn))) 1628 (list (format "help ('%s');\n" fn)))
1626 (let ((lines inferior-octave-output-list) 1629 (let ((lines inferior-octave-output-list)
1627 (inhibit-read-only t)) 1630 (inhibit-read-only t))
1628 (when (string-match "error: \\(.*\\)$" (car lines)) 1631 (when (string-match "error: \\(.*\\)$" (car lines))
@@ -1658,12 +1661,15 @@ if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n"
1658 (help-insert-xref-button (file-relative-name file dir) 1661 (help-insert-xref-button (file-relative-name file dir)
1659 'octave-help-file fn) 1662 'octave-help-file fn)
1660 (insert "'"))) 1663 (insert "'")))
1661 ;; Make 'See also' clickable 1664 ;; Make 'See also' clickable.
1662 (with-syntax-table octave-mode-syntax-table 1665 (with-syntax-table octave-mode-syntax-table
1663 (when (re-search-forward "^\\s-*See also:" nil t) 1666 (when (re-search-forward "^\\s-*See also:" nil t)
1664 (let ((end (save-excursion (re-search-forward "^\\s-*$" nil t)))) 1667 (let ((end (save-excursion (re-search-forward "^\\s-*$" nil t))))
1665 (while (re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" end t) 1668 (while (re-search-forward
1666 (make-text-button (match-beginning 0) (match-end 0) 1669 ;; Match operators and symbols.
1670 "\\(?1:\\s.+?\\)\\(?:$\\|[,;]\\|\\s-\\)\\|\\_<\\(?1:\\(?:\\sw\\|\\s_\\)+\\)\\_>"
1671 end t)
1672 (make-text-button (match-beginning 1) (match-end 1)
1667 :type 'octave-help-function))))) 1673 :type 'octave-help-function)))))
1668 (octave-help-mode))))) 1674 (octave-help-mode)))))
1669 1675
@@ -1716,12 +1722,13 @@ Functions implemented in C++ can be found if
1716 (interactive (list (octave-completing-read))) 1722 (interactive (list (octave-completing-read)))
1717 (require 'etags) 1723 (require 'etags)
1718 (let ((orig (point))) 1724 (let ((orig (point)))
1719 (if (octave-goto-function-definition fn) 1725 (if (and (derived-mode-p 'octave-mode)
1726 (octave-goto-function-definition fn))
1720 (ring-insert find-tag-marker-ring (copy-marker orig)) 1727 (ring-insert find-tag-marker-ring (copy-marker orig))
1721 (inferior-octave-send-list-and-digest 1728 (inferior-octave-send-list-and-digest
1722 ;; help NAME is more verbose 1729 ;; help NAME is more verbose
1723 (list (format "\ 1730 (list (format "\
1724if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n" 1731if iskeyword('%s') disp('`%s'' is a keyword') else which('%s') endif\n"
1725 fn fn fn))) 1732 fn fn fn)))
1726 (let (line file) 1733 (let (line file)
1727 ;; Skip garbage lines such as 1734 ;; Skip garbage lines such as
@@ -1738,6 +1745,5 @@ if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n"
1738 (find-file file) 1745 (find-file file)
1739 (octave-goto-function-definition fn))))))) 1746 (octave-goto-function-definition fn)))))))
1740 1747
1741
1742(provide 'octave) 1748(provide 'octave)
1743;;; octave.el ends here 1749;;; octave.el ends here