From: Leo Liu Date: Wed, 12 Jun 2013 02:37:38 +0000 (+0800) Subject: * progmodes/octave.el (inferior-octave-startup) X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2016^2~145^2~10 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=daabf15ad87707e788810b1c780ff3a31bb757b4;p=emacs.git * 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. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f3ea1419873..50eb27472d5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,19 @@ +2013-06-12 Leo Liu + + * 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. + 2013-06-12 Stefan Monnier * 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." :group 'octave :version "24.4") -(defcustom inferior-octave-startup-args nil +(defcustom inferior-octave-startup-args '("-i" "--no-line-editing") "List of command line arguments for the inferior Octave process. For example, for suppressing the startup message and using `traditional' -mode, set this to (\"-q\" \"--traditional\")." +mode, include \"-q\" and \"--traditional\"." :type '(repeat string) - :group 'octave) + :group 'octave + :version "24.4") (defcustom inferior-octave-mode-hook nil "Hook to be run when Inferior Octave mode is started." @@ -723,13 +724,13 @@ startup file, `~/.emacs-octave'." (substring inferior-octave-buffer 1 -1) inferior-octave-buffer inferior-octave-program - (append (list "-i" "--no-line-editing") - ;; --no-gui is introduced in Octave > 3.7 - (when (zerop (process-file inferior-octave-program - nil nil nil - "--no-gui" "--help")) - (list "--no-gui")) - inferior-octave-startup-args)))) + (append + inferior-octave-startup-args + ;; --no-gui is introduced in Octave > 3.7 + (and (not (member "--no-gui" inferior-octave-startup-args)) + (zerop (process-file inferior-octave-program + nil nil nil "--no-gui" "--help")) + '("--no-gui")))))) (set-process-filter proc 'inferior-octave-output-digest) (setq inferior-octave-process proc inferior-octave-output-list nil @@ -759,10 +760,10 @@ startup file, `~/.emacs-octave'." (inferior-octave-send-list-and-digest (list "PS2\n")) (when (string-match "\\(PS2\\|ans\\) = *$" (car inferior-octave-output-list)) - (inferior-octave-send-list-and-digest (list "PS2 (\"> \");\n"))) + (inferior-octave-send-list-and-digest (list "PS2 ('> ');\n"))) (inferior-octave-send-list-and-digest - (list "disp(getenv(\"OCTAVE_SRCDIR\"))\n")) + (list "disp (getenv ('OCTAVE_SRCDIR'))\n")) (process-put proc 'octave-srcdir (unless (equal (car inferior-octave-output-list) "") (car inferior-octave-output-list))) @@ -771,19 +772,19 @@ startup file, `~/.emacs-octave'." (inferior-octave-send-list-and-digest (list "more off;\n" (unless (equal inferior-octave-output-string ">> ") - "PS1 (\"\\\\s> \");\n") + "PS1 ('\\\\s> ');\n") (when (and inferior-octave-startup-file (file-exists-p inferior-octave-startup-file)) - (format "source (\"%s\");\n" inferior-octave-startup-file)))) + (format "source ('%s');\n" inferior-octave-startup-file)))) (when inferior-octave-output-list (insert-before-markers (mapconcat 'identity inferior-octave-output-list "\n"))) ;; And finally, everything is back to normal. (set-process-filter proc 'comint-output-filter) - ;; Just in case, to be sure a cd in the startup file - ;; won't have detrimental effects. - (inferior-octave-resync-dirs) + ;; Just in case, to be sure a cd in the startup file won't have + ;; detrimental effects. + (with-demoted-errors (inferior-octave-resync-dirs)) ;; Generate a proper prompt, which is critical to ;; `comint-history-isearch-backward-regexp'. Bug#14433. (comint-send-string proc "\n"))) @@ -799,7 +800,7 @@ startup file, `~/.emacs-octave'." (unless (and (equal (car cache) command) (< (float-time) (+ 5 (cadr cache)))) (inferior-octave-send-list-and-digest - (list (concat "completion_matches (\"" command "\");\n"))) + (list (format "completion_matches ('%s');\n" command))) (setq cache (list command (float-time) (delete-consecutive-dups (sort inferior-octave-output-list 'string-lessp))))) @@ -898,8 +899,8 @@ output is passed to the filter `inferior-octave-output-digest'." "Tracks `cd' commands issued to the inferior Octave process. Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused." (when inferior-octave-directory-tracker-resync - (setq inferior-octave-directory-tracker-resync nil) - (inferior-octave-resync-dirs)) + (or (inferior-octave-resync-dirs 'noerror) + (setq inferior-octave-directory-tracker-resync nil))) (cond ((string-match "^[ \t]*cd[ \t;]*$" string) (cd "~")) @@ -911,13 +912,17 @@ Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused." (error-message-string err) (match-string 1 string))))))) -(defun inferior-octave-resync-dirs () +(defun inferior-octave-resync-dirs (&optional noerror) "Resync the buffer's idea of the current directory. This command queries the inferior Octave process about its current directory and makes this the current buffer's default directory." (interactive) (inferior-octave-send-list-and-digest '("disp (pwd ())\n")) - (cd (car inferior-octave-output-list))) + (condition-case err + (progn + (cd (car inferior-octave-output-list)) + t) + (error (unless noerror (signal (car err) (cdr err)))))) (defcustom inferior-octave-minimal-columns 80 "The minimal column width for the inferior Octave process." @@ -935,7 +940,7 @@ directory and makes this the current buffer's default directory." (when (and inferior-octave-process (process-live-p inferior-octave-process)) (inferior-octave-send-list-and-digest - (list (format "putenv(\"COLUMNS\", \"%s\");\n" width))))))) + (list (format "putenv ('COLUMNS', '%s');\n" width))))))) ;;; Miscellaneous useful functions @@ -989,7 +994,7 @@ directory and makes this the current buffer's default directory." (setq found t))) (unless found (goto-char orig)) found)))) - (pcase (file-name-extension (buffer-file-name)) + (pcase (and buffer-file-name (file-name-extension buffer-file-name)) (`"cc" (funcall search "\\_" end t) - (make-text-button (match-beginning 0) (match-end 0) + (while (re-search-forward + ;; Match operators and symbols. + "\\(?1:\\s.+?\\)\\(?:$\\|[,;]\\|\\s-\\)\\|\\_<\\(?1:\\(?:\\sw\\|\\s_\\)+\\)\\_>" + end t) + (make-text-button (match-beginning 1) (match-end 1) :type 'octave-help-function))))) (octave-help-mode))))) @@ -1716,12 +1722,13 @@ Functions implemented in C++ can be found if (interactive (list (octave-completing-read))) (require 'etags) (let ((orig (point))) - (if (octave-goto-function-definition fn) + (if (and (derived-mode-p 'octave-mode) + (octave-goto-function-definition fn)) (ring-insert find-tag-marker-ring (copy-marker orig)) (inferior-octave-send-list-and-digest ;; help NAME is more verbose (list (format "\ -if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n" +if iskeyword('%s') disp('`%s'' is a keyword') else which('%s') endif\n" fn fn fn))) (let (line file) ;; Skip garbage lines such as @@ -1738,6 +1745,5 @@ if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n" (find-file file) (octave-goto-function-definition fn))))))) - (provide 'octave) ;;; octave.el ends here