diff options
| author | Leo Liu | 2013-05-11 21:22:06 +0800 |
|---|---|---|
| committer | Leo Liu | 2013-05-11 21:22:06 +0800 |
| commit | c8730c3abed1bbd336937575b91cb5fd1738abb3 (patch) | |
| tree | e41cc6b37d2edf7f77b3ff1219fce9e813d621c3 | |
| parent | 212e29f2e2b0df4ddc89de1208bef46625ae8ad4 (diff) | |
| download | emacs-c8730c3abed1bbd336937575b91cb5fd1738abb3.tar.gz emacs-c8730c3abed1bbd336937575b91cb5fd1738abb3.zip | |
* progmodes/octave.el (octave-indent-comment): Improve.
(octave-eldoc-message-style, octave-eldoc-cache): New variables.
(octave-eldoc-function-signatures, octave-eldoc-function): New
functions.
(octave-mode, inferior-octave-mode): Add eldoc support.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/progmodes/octave.el | 70 |
2 files changed, 77 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 6fdcb1e143b..49183dd9be3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-05-11 Leo Liu <sdl.web@gmail.com> | ||
| 2 | |||
| 3 | * progmodes/octave.el (octave-indent-comment): Improve. | ||
| 4 | (octave-eldoc-message-style, octave-eldoc-cache): New variables. | ||
| 5 | (octave-eldoc-function-signatures, octave-eldoc-function): New | ||
| 6 | functions. | ||
| 7 | (octave-mode, inferior-octave-mode): Add eldoc support. | ||
| 8 | |||
| 1 | 2013-05-11 Richard Stallman <rms@gnu.org> | 9 | 2013-05-11 Richard Stallman <rms@gnu.org> |
| 2 | 10 | ||
| 3 | * epa.el (epa-decrypt-file): Take output file name as argument | 11 | * epa.el (epa-decrypt-file): Take output file name as argument |
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index b2a21f2337a..b4fae808df6 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el | |||
| @@ -434,7 +434,9 @@ Non-nil means always go to the next Octave code line after sending." | |||
| 434 | "A function for `smie-indent-functions' (which see)." | 434 | "A function for `smie-indent-functions' (which see)." |
| 435 | (save-excursion | 435 | (save-excursion |
| 436 | (back-to-indentation) | 436 | (back-to-indentation) |
| 437 | (when (and (looking-at-p "\\s<") (not (looking-at-p "\\s<\\s<"))) | 437 | (when (and (not (octave-in-string-or-comment-p)) |
| 438 | (looking-at-p "\\s<\\(?:[^{}]\\|$\\)") | ||
| 439 | (not (looking-at-p "\\s<\\s<"))) | ||
| 438 | (comment-choose-indent)))) | 440 | (comment-choose-indent)))) |
| 439 | 441 | ||
| 440 | 442 | ||
| @@ -554,6 +556,7 @@ definitions can also be stored in files and used in batch mode." | |||
| 554 | (add-hook 'before-save-hook 'octave-sync-function-file-names nil t) | 556 | (add-hook 'before-save-hook 'octave-sync-function-file-names nil t) |
| 555 | (setq-local beginning-of-defun-function 'octave-beginning-of-defun) | 557 | (setq-local beginning-of-defun-function 'octave-beginning-of-defun) |
| 556 | (and octave-font-lock-texinfo-comment (octave-font-lock-texinfo-comment)) | 558 | (and octave-font-lock-texinfo-comment (octave-font-lock-texinfo-comment)) |
| 559 | (setq-local eldoc-documentation-function 'octave-eldoc-function) | ||
| 557 | 560 | ||
| 558 | (easy-menu-add octave-mode-menu)) | 561 | (easy-menu-add octave-mode-menu)) |
| 559 | 562 | ||
| @@ -658,6 +661,7 @@ in the Inferior Octave buffer.") | |||
| 658 | (setq font-lock-defaults '(inferior-octave-font-lock-keywords nil nil)) | 661 | (setq font-lock-defaults '(inferior-octave-font-lock-keywords nil nil)) |
| 659 | 662 | ||
| 660 | (setq-local info-lookup-mode 'octave-mode) | 663 | (setq-local info-lookup-mode 'octave-mode) |
| 664 | (setq-local eldoc-documentation-function 'octave-eldoc-function) | ||
| 661 | 665 | ||
| 662 | (setq comint-input-ring-file-name | 666 | (setq comint-input-ring-file-name |
| 663 | (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist") | 667 | (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist") |
| @@ -1484,6 +1488,70 @@ code line." | |||
| 1484 | 1488 | ||
| 1485 | 1489 | ||
| 1486 | 1490 | ||
| 1491 | (defcustom octave-eldoc-message-style 'auto | ||
| 1492 | "Octave eldoc message style: auto, oneline, multiline." | ||
| 1493 | :type '(choice (const :tag "Automatic" auto) | ||
| 1494 | (const :tag "One Line" oneline) | ||
| 1495 | (const :tag "Multi Line" multiline)) | ||
| 1496 | :group 'octave | ||
| 1497 | :version "24.4") | ||
| 1498 | |||
| 1499 | ;; (FN SIGNATURE1 SIGNATURE2 ...) | ||
| 1500 | (defvar octave-eldoc-cache nil) | ||
| 1501 | |||
| 1502 | (defun octave-eldoc-function-signatures (fn) | ||
| 1503 | (unless (equal fn (car octave-eldoc-cache)) | ||
| 1504 | (inferior-octave-send-list-and-digest | ||
| 1505 | (list (format "\ | ||
| 1506 | if ismember(exist(\"%s\"), [2 3 5 103]) print_usage(\"%s\") endif\n" | ||
| 1507 | fn fn))) | ||
| 1508 | (let (result) | ||
| 1509 | (dolist (line inferior-octave-output-list) | ||
| 1510 | (when (string-match | ||
| 1511 | "\\s-*\\(?:--[^:]+\\|usage\\):\\s-*\\(.*\\)$" | ||
| 1512 | line) | ||
| 1513 | (push (match-string 1 line) result))) | ||
| 1514 | (setq octave-eldoc-cache | ||
| 1515 | (cons (substring-no-properties fn) | ||
| 1516 | (nreverse result))))) | ||
| 1517 | (cdr octave-eldoc-cache)) | ||
| 1518 | |||
| 1519 | (defun octave-eldoc-function () | ||
| 1520 | "A function for `eldoc-documentation-function' (which see)." | ||
| 1521 | (when (and inferior-octave-process | ||
| 1522 | (process-live-p inferior-octave-process)) | ||
| 1523 | (let* ((ppss (syntax-ppss)) | ||
| 1524 | (paren-pos (cadr ppss)) | ||
| 1525 | (fn (save-excursion | ||
| 1526 | (if (and paren-pos | ||
| 1527 | ;; PAREN-POS must be after the prompt | ||
| 1528 | (>= paren-pos | ||
| 1529 | (if (eq (get-buffer-process (current-buffer)) | ||
| 1530 | inferior-octave-process) | ||
| 1531 | (process-mark inferior-octave-process) | ||
| 1532 | (point-min))) | ||
| 1533 | (or (not (eq (get-buffer-process (current-buffer)) | ||
| 1534 | inferior-octave-process)) | ||
| 1535 | (< (process-mark inferior-octave-process) | ||
| 1536 | paren-pos)) | ||
| 1537 | (eq (char-after paren-pos) ?\()) | ||
| 1538 | (goto-char paren-pos) | ||
| 1539 | (setq paren-pos nil)) | ||
| 1540 | (when (or (< (skip-syntax-backward "-") 0) paren-pos) | ||
| 1541 | (thing-at-point 'symbol)))) | ||
| 1542 | (sigs (and fn (octave-eldoc-function-signatures fn))) | ||
| 1543 | (oneline (mapconcat 'identity sigs | ||
| 1544 | (propertize " | " 'face 'warning))) | ||
| 1545 | (multiline (mapconcat (lambda (s) (concat "-- " s)) sigs "\n"))) | ||
| 1546 | ;; | ||
| 1547 | ;; Return the value according to style. | ||
| 1548 | (pcase octave-eldoc-message-style | ||
| 1549 | (`auto (if (< (length oneline) (window-width (minibuffer-window))) | ||
| 1550 | oneline | ||
| 1551 | multiline)) | ||
| 1552 | (`oneline oneline) | ||
| 1553 | (`multiline multiline))))) | ||
| 1554 | |||
| 1487 | (defcustom octave-help-buffer "*Octave Help*" | 1555 | (defcustom octave-help-buffer "*Octave Help*" |
| 1488 | "Buffer name for `octave-help'." | 1556 | "Buffer name for `octave-help'." |
| 1489 | :type 'string | 1557 | :type 'string |