diff options
| author | Kenichi Handa | 2012-08-16 21:25:17 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2012-08-16 21:25:17 +0900 |
| commit | d75ffb4ed0b2e72a9361a07d16a5c884a9459728 (patch) | |
| tree | 8ac5a6a8ae033fef7fbc7fb7b09a703ef4b0ed5b /lisp/progmodes | |
| parent | 69c41c4070c86baac11a627e9c3d366420aeb7cc (diff) | |
| parent | 250c8ab9b8f6322959fa3122db83944c30c3894b (diff) | |
| download | emacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.tar.gz emacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.zip | |
merge trunk
Diffstat (limited to 'lisp/progmodes')
| -rw-r--r-- | lisp/progmodes/autoconf.el | 11 | ||||
| -rw-r--r-- | lisp/progmodes/bug-reference.el | 3 | ||||
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 18 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 6 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/cc-menus.el | 8 | ||||
| -rw-r--r-- | lisp/progmodes/cmacexp.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/compile.el | 6 | ||||
| -rw-r--r-- | lisp/progmodes/cperl-mode.el | 11 | ||||
| -rw-r--r-- | lisp/progmodes/ebnf-yac.el | 4 | ||||
| -rw-r--r-- | lisp/progmodes/ebnf2ps.el | 4 | ||||
| -rw-r--r-- | lisp/progmodes/gdb-mi.el | 75 | ||||
| -rw-r--r-- | lisp/progmodes/gud.el | 7 | ||||
| -rw-r--r-- | lisp/progmodes/perl-mode.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 930 | ||||
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 219 | ||||
| -rw-r--r-- | lisp/progmodes/sh-script.el | 23 | ||||
| -rw-r--r-- | lisp/progmodes/subword.el | 28 | ||||
| -rw-r--r-- | lisp/progmodes/vhdl-mode.el | 6 | ||||
| -rw-r--r-- | lisp/progmodes/which-func.el | 4 |
20 files changed, 803 insertions, 566 deletions
diff --git a/lisp/progmodes/autoconf.el b/lisp/progmodes/autoconf.el index 3225fef2dfa..ac3a7282952 100644 --- a/lisp/progmodes/autoconf.el +++ b/lisp/progmodes/autoconf.el | |||
| @@ -35,20 +35,18 @@ | |||
| 35 | 35 | ||
| 36 | ;;; Code: | 36 | ;;; Code: |
| 37 | 37 | ||
| 38 | (defvar font-lock-syntactic-keywords) | ||
| 39 | |||
| 40 | (defvar autoconf-mode-map (make-sparse-keymap)) | 38 | (defvar autoconf-mode-map (make-sparse-keymap)) |
| 41 | 39 | ||
| 42 | (defvar autoconf-mode-hook nil | 40 | (defvar autoconf-mode-hook nil |
| 43 | "Hook run by `autoconf-mode'.") | 41 | "Hook run by `autoconf-mode'.") |
| 44 | 42 | ||
| 45 | (defconst autoconf-definition-regexp | 43 | (defconst autoconf-definition-regexp |
| 46 | "AC_\\(SUBST\\|DEFINE\\(_UNQUOTED\\)?\\)(\\[*\\(\\sw+\\)\\]*") | 44 | "A\\(?:H_TEMPLATE\\|C_\\(?:SUBST\\|DEFINE\\(?:_UNQUOTED\\)?\\)\\)(\\[*\\(\\sw+\\)\\]*") |
| 47 | 45 | ||
| 48 | (defvar autoconf-font-lock-keywords | 46 | (defvar autoconf-font-lock-keywords |
| 49 | `(("\\_<A[CHMS]_\\sw+" . font-lock-keyword-face) | 47 | `(("\\_<A[CHMS]_\\sw+" . font-lock-keyword-face) |
| 50 | (,autoconf-definition-regexp | 48 | (,autoconf-definition-regexp |
| 51 | 3 font-lock-function-name-face) | 49 | 1 font-lock-function-name-face) |
| 52 | ;; Are any other M4 keywords really appropriate for configure.ac, | 50 | ;; Are any other M4 keywords really appropriate for configure.ac, |
| 53 | ;; given that we do `dnl'? | 51 | ;; given that we do `dnl'? |
| 54 | ("changequote" . font-lock-keyword-face))) | 52 | ("changequote" . font-lock-keyword-face))) |
| @@ -61,7 +59,7 @@ | |||
| 61 | table)) | 59 | table)) |
| 62 | 60 | ||
| 63 | (defvar autoconf-imenu-generic-expression | 61 | (defvar autoconf-imenu-generic-expression |
| 64 | (list (list nil autoconf-definition-regexp 3))) | 62 | (list (list nil autoconf-definition-regexp 1))) |
| 65 | 63 | ||
| 66 | ;; It's not clear how best to implement this. | 64 | ;; It's not clear how best to implement this. |
| 67 | (defun autoconf-current-defun-function () | 65 | (defun autoconf-current-defun-function () |
| @@ -71,10 +69,11 @@ searching backwards at another AC_... command." | |||
| 71 | (save-excursion | 69 | (save-excursion |
| 72 | (with-syntax-table (copy-syntax-table autoconf-mode-syntax-table) | 70 | (with-syntax-table (copy-syntax-table autoconf-mode-syntax-table) |
| 73 | (modify-syntax-entry ?_ "w") | 71 | (modify-syntax-entry ?_ "w") |
| 72 | (skip-syntax-forward "w" (line-end-position)) | ||
| 74 | (if (re-search-backward autoconf-definition-regexp | 73 | (if (re-search-backward autoconf-definition-regexp |
| 75 | (save-excursion (beginning-of-defun) (point)) | 74 | (save-excursion (beginning-of-defun) (point)) |
| 76 | t) | 75 | t) |
| 77 | (match-string-no-properties 3))))) | 76 | (match-string-no-properties 1))))) |
| 78 | 77 | ||
| 79 | ;;;###autoload | 78 | ;;;###autoload |
| 80 | (define-derived-mode autoconf-mode prog-mode "Autoconf" | 79 | (define-derived-mode autoconf-mode prog-mode "Autoconf" |
diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el index 48ef5da12ae..0a7d65c1fa4 100644 --- a/lisp/progmodes/bug-reference.el +++ b/lisp/progmodes/bug-reference.el | |||
| @@ -30,6 +30,8 @@ | |||
| 30 | ;; Two minor modes are provided. One works on any text in the buffer; | 30 | ;; Two minor modes are provided. One works on any text in the buffer; |
| 31 | ;; the other operates only on comments and strings. | 31 | ;; the other operates only on comments and strings. |
| 32 | 32 | ||
| 33 | ;;; Code: | ||
| 34 | |||
| 33 | (defvar bug-reference-map | 35 | (defvar bug-reference-map |
| 34 | (let ((map (make-sparse-keymap))) | 36 | (let ((map (make-sparse-keymap))) |
| 35 | (define-key map [mouse-2] 'bug-reference-push-button) | 37 | (define-key map [mouse-2] 'bug-reference-push-button) |
| @@ -154,4 +156,5 @@ the mode if ARG is omitted or nil." | |||
| 154 | (widen) | 156 | (widen) |
| 155 | (bug-reference-unfontify (point-min) (point-max))))) | 157 | (bug-reference-unfontify (point-min) (point-max))))) |
| 156 | 158 | ||
| 159 | (provide 'bug-reference) | ||
| 157 | ;;; bug-reference.el ends here | 160 | ;;; bug-reference.el ends here |
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 94b296bf59e..7cd0a0b0ae2 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -1826,14 +1826,16 @@ with a brace block." | |||
| 1826 | ;; DEFFLAGSET(syslog_opt_flags,LOG_PID ...) ==> syslog_opt_flags | 1826 | ;; DEFFLAGSET(syslog_opt_flags,LOG_PID ...) ==> syslog_opt_flags |
| 1827 | (match-string-no-properties 1)) | 1827 | (match-string-no-properties 1)) |
| 1828 | 1828 | ||
| 1829 | ;; Objective-C method starting with + or -. | 1829 | ;; Objc selectors. |
| 1830 | ((and (derived-mode-p 'objc-mode) | 1830 | ((assq 'objc-method-intro (c-guess-basic-syntax)) |
| 1831 | (looking-at "[-+]\s*(")) | 1831 | (let ((bound (save-excursion (c-end-of-statement) (point))) |
| 1832 | (when (c-syntactic-re-search-forward ")\s*" nil t) | 1832 | (kw-re (concat "\\(?:" c-symbol-key "\\)?:")) |
| 1833 | (c-forward-token-2) | 1833 | (stretches)) |
| 1834 | (setq name-end (point)) | 1834 | (when (c-syntactic-re-search-forward c-symbol-key bound t t t) |
| 1835 | (c-backward-token-2) | 1835 | (push (match-string-no-properties 0) stretches) |
| 1836 | (buffer-substring-no-properties (point) name-end))) | 1836 | (while (c-syntactic-re-search-forward kw-re bound t t t) |
| 1837 | (push (match-string-no-properties 0) stretches))) | ||
| 1838 | (apply 'concat (nreverse stretches)))) | ||
| 1837 | 1839 | ||
| 1838 | (t | 1840 | (t |
| 1839 | ;; Normal function or initializer. | 1841 | ;; Normal function or initializer. |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 82aee7bdbb9..142ec4cdd66 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -1688,6 +1688,7 @@ comment at the start of cc-engine.el for more info." | |||
| 1688 | ;; high as possible. | 1688 | ;; high as possible. |
| 1689 | (setq rung-pos (point))) | 1689 | (setq rung-pos (point))) |
| 1690 | 1690 | ||
| 1691 | (with-silent-modifications | ||
| 1691 | (while | 1692 | (while |
| 1692 | (progn | 1693 | (progn |
| 1693 | (while | 1694 | (while |
| @@ -1843,7 +1844,7 @@ comment at the start of cc-engine.el for more info." | |||
| 1843 | (1- last-put-in-sws-pos)) | 1844 | (1- last-put-in-sws-pos)) |
| 1844 | (c-remove-is-and-in-sws (1- last-put-in-sws-pos) | 1845 | (c-remove-is-and-in-sws (1- last-put-in-sws-pos) |
| 1845 | last-put-in-sws-pos)))) | 1846 | last-put-in-sws-pos)))) |
| 1846 | ))) | 1847 | )))) |
| 1847 | 1848 | ||
| 1848 | (defun c-backward-sws () | 1849 | (defun c-backward-sws () |
| 1849 | ;; Used by `c-backward-syntactic-ws' to implement the unbounded search. | 1850 | ;; Used by `c-backward-syntactic-ws' to implement the unbounded search. |
| @@ -1881,6 +1882,7 @@ comment at the start of cc-engine.el for more info." | |||
| 1881 | (goto-char (setq rung-pos rung-is-marked)) | 1882 | (goto-char (setq rung-pos rung-is-marked)) |
| 1882 | (goto-char simple-ws-beg)) | 1883 | (goto-char simple-ws-beg)) |
| 1883 | 1884 | ||
| 1885 | (with-silent-modifications | ||
| 1884 | (while | 1886 | (while |
| 1885 | (progn | 1887 | (progn |
| 1886 | (while | 1888 | (while |
| @@ -2066,7 +2068,7 @@ comment at the start of cc-engine.el for more info." | |||
| 2066 | last-put-in-sws-pos) | 2068 | last-put-in-sws-pos) |
| 2067 | (c-remove-is-and-in-sws last-put-in-sws-pos | 2069 | (c-remove-is-and-in-sws last-put-in-sws-pos |
| 2068 | (1+ last-put-in-sws-pos))))) | 2070 | (1+ last-put-in-sws-pos))))) |
| 2069 | ))) | 2071 | )))) |
| 2070 | 2072 | ||
| 2071 | 2073 | ||
| 2072 | ;; Other whitespace tools | 2074 | ;; Other whitespace tools |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 493f3db0961..78be8ac2cc4 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -578,7 +578,7 @@ keyword. It's unspecified how far it matches. Does not contain a \\| | |||
| 578 | operator at the top level." | 578 | operator at the top level." |
| 579 | t (concat "[" c-alpha "_]") | 579 | t (concat "[" c-alpha "_]") |
| 580 | java (concat "[" c-alpha "_@]") | 580 | java (concat "[" c-alpha "_@]") |
| 581 | objc (concat "[" c-alpha "@]") | 581 | objc (concat "[" c-alpha "_@]") |
| 582 | pike (concat "[" c-alpha "_`]")) | 582 | pike (concat "[" c-alpha "_`]")) |
| 583 | (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start)) | 583 | (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start)) |
| 584 | 584 | ||
diff --git a/lisp/progmodes/cc-menus.el b/lisp/progmodes/cc-menus.el index a53d65f6307..76e3002abd2 100644 --- a/lisp/progmodes/cc-menus.el +++ b/lisp/progmodes/cc-menus.el | |||
| @@ -399,14 +399,10 @@ Example: | |||
| 399 | str2 "@protocol"))) | 399 | str2 "@protocol"))) |
| 400 | (setq str (cc-imenu-objc-remove-white-space str)) | 400 | (setq str (cc-imenu-objc-remove-white-space str)) |
| 401 | (setq methodlist (cons (cons str2 | 401 | (setq methodlist (cons (cons str2 |
| 402 | (match-beginning langnum)) | 402 | (match-beginning langnum)) |
| 403 | methodlist)) | 403 | methodlist)) |
| 404 | (setq toplist (cons nil (cons (cons str | 404 | (setq toplist (cons (cons str methodlist) toplist) |
| 405 | methodlist) toplist)) | ||
| 406 | methodlist nil)))) | 405 | methodlist nil)))) |
| 407 | ;; | ||
| 408 | (if (eq (car toplist) nil) | ||
| 409 | (setq toplist (cdr toplist))) | ||
| 410 | 406 | ||
| 411 | ;; In this buffer, there is only one or zero @{interface|implementation|protocol}. | 407 | ;; In this buffer, there is only one or zero @{interface|implementation|protocol}. |
| 412 | (if (< classcount 2) | 408 | (if (< classcount 2) |
diff --git a/lisp/progmodes/cmacexp.el b/lisp/progmodes/cmacexp.el index 0feefd99715..943b5c6a067 100644 --- a/lisp/progmodes/cmacexp.el +++ b/lisp/progmodes/cmacexp.el | |||
| @@ -80,7 +80,7 @@ | |||
| 80 | ;; making comments visible in the expansion. | 80 | ;; making comments visible in the expansion. |
| 81 | ;; - All work is done in core memory, no need for temporary files. | 81 | ;; - All work is done in core memory, no need for temporary files. |
| 82 | 82 | ||
| 83 | ;; ACKNOWLEDGEMENTS ================================================== | 83 | ;; ACKNOWLEDGMENTS =================================================== |
| 84 | 84 | ||
| 85 | ;; A lot of thanks to Don Maszle who did a great work of testing, bug | 85 | ;; A lot of thanks to Don Maszle who did a great work of testing, bug |
| 86 | ;; reporting and suggestion of new features. This work has been | 86 | ;; reporting and suggestion of new features. This work has been |
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index c008e1c4da3..21a323d8b45 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el | |||
| @@ -684,13 +684,13 @@ starting the compilation process." | |||
| 684 | (t (:inverse-video t :weight bold))) | 684 | (t (:inverse-video t :weight bold))) |
| 685 | "Face for Compilation mode's \"error\" mode line indicator." | 685 | "Face for Compilation mode's \"error\" mode line indicator." |
| 686 | :group 'compilation | 686 | :group 'compilation |
| 687 | :version "24.2") | 687 | :version "24.3") |
| 688 | 688 | ||
| 689 | (defface compilation-mode-line-run | 689 | (defface compilation-mode-line-run |
| 690 | '((t :inherit compilation-warning)) | 690 | '((t :inherit compilation-warning)) |
| 691 | "Face for Compilation mode's \"running\" mode line indicator." | 691 | "Face for Compilation mode's \"running\" mode line indicator." |
| 692 | :group 'compilation | 692 | :group 'compilation |
| 693 | :version "24.2") | 693 | :version "24.3") |
| 694 | 694 | ||
| 695 | (defface compilation-mode-line-exit | 695 | (defface compilation-mode-line-exit |
| 696 | '((default :inherit compilation-info) | 696 | '((default :inherit compilation-info) |
| @@ -700,7 +700,7 @@ starting the compilation process." | |||
| 700 | (t (:weight bold))) | 700 | (t (:weight bold))) |
| 701 | "Face for Compilation mode's \"exit\" mode line indicator." | 701 | "Face for Compilation mode's \"exit\" mode line indicator." |
| 702 | :group 'compilation | 702 | :group 'compilation |
| 703 | :version "24.2") | 703 | :version "24.3") |
| 704 | 704 | ||
| 705 | (defface compilation-line-number | 705 | (defface compilation-line-number |
| 706 | '((t :inherit font-lock-keyword-face)) | 706 | '((t :inherit font-lock-keyword-face)) |
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index f0499424952..e1430b67e99 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el | |||
| @@ -1838,7 +1838,13 @@ or as help on variables `cperl-tips', `cperl-problems', | |||
| 1838 | (set (make-local-variable 'cperl-syntax-done-to) nil) | 1838 | (set (make-local-variable 'cperl-syntax-done-to) nil) |
| 1839 | (set (make-local-variable 'syntax-propertize-function) | 1839 | (set (make-local-variable 'syntax-propertize-function) |
| 1840 | (lambda (start end) | 1840 | (lambda (start end) |
| 1841 | (goto-char start) (cperl-fontify-syntaxically end)))) | 1841 | (goto-char start) |
| 1842 | ;; Even if cperl-fontify-syntaxically has already gone | ||
| 1843 | ;; beyond `start', syntax-propertize has just removed | ||
| 1844 | ;; syntax-table properties between start and end, so we have | ||
| 1845 | ;; to re-apply them. | ||
| 1846 | (setq cperl-syntax-done-to start) | ||
| 1847 | (cperl-fontify-syntaxically end)))) | ||
| 1842 | (make-local-variable 'parse-sexp-lookup-properties) | 1848 | (make-local-variable 'parse-sexp-lookup-properties) |
| 1843 | ;; Do not introduce variable if not needed, we check it! | 1849 | ;; Do not introduce variable if not needed, we check it! |
| 1844 | (set 'parse-sexp-lookup-properties t) | 1850 | (set 'parse-sexp-lookup-properties t) |
| @@ -3497,7 +3503,8 @@ Works before syntax recognition is done." | |||
| 3497 | (if end | 3503 | (if end |
| 3498 | ;; Do the same for end, going small steps | 3504 | ;; Do the same for end, going small steps |
| 3499 | (save-excursion | 3505 | (save-excursion |
| 3500 | (while (and end (get-text-property end 'syntax-type)) | 3506 | (while (and end (< end (point-max)) |
| 3507 | (get-text-property end 'syntax-type)) | ||
| 3501 | (setq pos end | 3508 | (setq pos end |
| 3502 | end (next-single-property-change end 'syntax-type nil (point-max))) | 3509 | end (next-single-property-change end 'syntax-type nil (point-max))) |
| 3503 | (if end (progn (goto-char end) | 3510 | (if end (progn (goto-char end) |
diff --git a/lisp/progmodes/ebnf-yac.el b/lisp/progmodes/ebnf-yac.el index 56c8dc57e96..8e0ca260928 100644 --- a/lisp/progmodes/ebnf-yac.el +++ b/lisp/progmodes/ebnf-yac.el | |||
| @@ -73,8 +73,8 @@ | |||
| 73 | ;; example: this_is_a_valid.name, Another_EXAMPLE, mIxEd.CaSe. | 73 | ;; example: this_is_a_valid.name, Another_EXAMPLE, mIxEd.CaSe. |
| 74 | ;; | 74 | ;; |
| 75 | ;; | 75 | ;; |
| 76 | ;; Acknowledgements | 76 | ;; Acknowledgments |
| 77 | ;; ---------------- | 77 | ;; --------------- |
| 78 | ;; | 78 | ;; |
| 79 | ;; Thanks to Matthew K. Junker <junker@alum.mit.edu> for the suggestion to deal | 79 | ;; Thanks to Matthew K. Junker <junker@alum.mit.edu> for the suggestion to deal |
| 80 | ;; with %right, %left and %prec pragmas. His suggestion was extended to deal | 80 | ;; with %right, %left and %prec pragmas. His suggestion was extended to deal |
diff --git a/lisp/progmodes/ebnf2ps.el b/lisp/progmodes/ebnf2ps.el index b7cbdcc7018..cdbaf4708a7 100644 --- a/lisp/progmodes/ebnf2ps.el +++ b/lisp/progmodes/ebnf2ps.el | |||
| @@ -1128,8 +1128,8 @@ Please send all bug fixes and enhancements to | |||
| 1128 | ;; . Optimizations... | 1128 | ;; . Optimizations... |
| 1129 | ;; | 1129 | ;; |
| 1130 | ;; | 1130 | ;; |
| 1131 | ;; Acknowledgements | 1131 | ;; Acknowledgments |
| 1132 | ;; ---------------- | 1132 | ;; --------------- |
| 1133 | ;; | 1133 | ;; |
| 1134 | ;; Thanks to Eli Zaretskii <eliz@gnu.org> for some doc fixes. | 1134 | ;; Thanks to Eli Zaretskii <eliz@gnu.org> for some doc fixes. |
| 1135 | ;; | 1135 | ;; |
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 23a34b85194..0a99c2f5c24 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el | |||
| @@ -944,11 +944,16 @@ no input, and GDB is waiting for input." | |||
| 944 | (defun gdb-tooltip-print (expr) | 944 | (defun gdb-tooltip-print (expr) |
| 945 | (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer) | 945 | (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer) |
| 946 | (goto-char (point-min)) | 946 | (goto-char (point-min)) |
| 947 | (if (re-search-forward ".*value=\\(\".*\"\\)" nil t) | 947 | (cond |
| 948 | (tooltip-show | 948 | ((re-search-forward ".*value=\\(\".*\"\\)" nil t) |
| 949 | (concat expr " = " (read (match-string 1))) | 949 | (tooltip-show |
| 950 | (or gud-tooltip-echo-area | 950 | (concat expr " = " (read (match-string 1))) |
| 951 | (not (display-graphic-p))))))) | 951 | (or gud-tooltip-echo-area |
| 952 | (not (display-graphic-p))))) | ||
| 953 | ((re-search-forward "msg=\\(\".+\"\\)$" nil t) | ||
| 954 | (tooltip-show (read (match-string 1)) | ||
| 955 | (or gud-tooltip-echo-area | ||
| 956 | (not (display-graphic-p)))))))) | ||
| 952 | 957 | ||
| 953 | ;; If expr is a macro for a function don't print because of possible dangerous | 958 | ;; If expr is a macro for a function don't print because of possible dangerous |
| 954 | ;; side-effects. Also printing a function within a tooltip generates an | 959 | ;; side-effects. Also printing a function within a tooltip generates an |
| @@ -958,7 +963,7 @@ no input, and GDB is waiting for input." | |||
| 958 | (goto-char (point-min)) | 963 | (goto-char (point-min)) |
| 959 | (if (search-forward "expands to: " nil t) | 964 | (if (search-forward "expands to: " nil t) |
| 960 | (unless (looking-at "\\S-+.*(.*).*") | 965 | (unless (looking-at "\\S-+.*(.*).*") |
| 961 | (gdb-input (concat "-data-evaluate-expression " expr) | 966 | (gdb-input (concat "-data-evaluate-expression \"" expr "\"") |
| 962 | `(lambda () (gdb-tooltip-print ,expr))))))) | 967 | `(lambda () (gdb-tooltip-print ,expr))))))) |
| 963 | 968 | ||
| 964 | (defun gdb-init-buffer () | 969 | (defun gdb-init-buffer () |
| @@ -1513,12 +1518,13 @@ DOC is an optional documentation string." | |||
| 1513 | ;; Set up inferior I/O. Needs GDB 6.4 onwards. | 1518 | ;; Set up inferior I/O. Needs GDB 6.4 onwards. |
| 1514 | (set-process-filter proc 'gdb-inferior-filter) | 1519 | (set-process-filter proc 'gdb-inferior-filter) |
| 1515 | (set-process-sentinel proc 'gdb-inferior-io-sentinel) | 1520 | (set-process-sentinel proc 'gdb-inferior-io-sentinel) |
| 1516 | (gdb-input | 1521 | ;; The process can run on a remote host. |
| 1517 | (concat "-inferior-tty-set " | 1522 | (let ((tty (or (process-get proc 'remote-tty) |
| 1518 | ;; The process can run on a remote host. | 1523 | (process-tty-name proc)))) |
| 1519 | (or (process-get proc 'remote-tty) | 1524 | (unless (or (null tty) |
| 1520 | (process-tty-name proc))) | 1525 | (string= tty "")) |
| 1521 | 'ignore)) | 1526 | (gdb-input |
| 1527 | (concat "-inferior-tty-set " tty) 'ignore)))) | ||
| 1522 | 1528 | ||
| 1523 | (defun gdb-inferior-io-sentinel (proc str) | 1529 | (defun gdb-inferior-io-sentinel (proc str) |
| 1524 | (when (eq (process-status proc) 'failed) | 1530 | (when (eq (process-status proc) 'failed) |
| @@ -2100,13 +2106,15 @@ current thread and update GDB buffers." | |||
| 2100 | (setq gdb-filter-output | 2106 | (setq gdb-filter-output |
| 2101 | (gdb-concat-output | 2107 | (gdb-concat-output |
| 2102 | gdb-filter-output | 2108 | gdb-filter-output |
| 2103 | (let ((error-message | 2109 | (if (string= output-field "\"\\n\"") |
| 2104 | (read output-field))) | 2110 | "" |
| 2105 | (put-text-property | 2111 | (let ((error-message |
| 2106 | 0 (length error-message) | 2112 | (read output-field))) |
| 2107 | 'face font-lock-warning-face | 2113 | (put-text-property |
| 2108 | error-message) | 2114 | 0 (length error-message) |
| 2109 | error-message)))) | 2115 | 'face font-lock-warning-face |
| 2116 | error-message) | ||
| 2117 | error-message))))) | ||
| 2110 | 2118 | ||
| 2111 | ;; Remove the trimmings from the console stream and send to GUD buffer | 2119 | ;; Remove the trimmings from the console stream and send to GUD buffer |
| 2112 | ;; (frontend MI commands should not print to this stream) | 2120 | ;; (frontend MI commands should not print to this stream) |
| @@ -2487,20 +2495,23 @@ HANDLER-NAME handler uses customization of CUSTOM-DEFUN. See | |||
| 2487 | (let ((file (bindat-get-field breakpoint 'fullname)) | 2495 | (let ((file (bindat-get-field breakpoint 'fullname)) |
| 2488 | (flag (bindat-get-field breakpoint 'enabled)) | 2496 | (flag (bindat-get-field breakpoint 'enabled)) |
| 2489 | (bptno (bindat-get-field breakpoint 'number))) | 2497 | (bptno (bindat-get-field breakpoint 'number))) |
| 2490 | (unless (file-exists-p file) | 2498 | (unless (and file (file-exists-p file)) |
| 2491 | (setq file (cdr (assoc bptno gdb-location-alist)))) | 2499 | (setq file (cdr (assoc bptno gdb-location-alist)))) |
| 2492 | (if (and file | 2500 | (if (or (null file) |
| 2493 | (not (string-equal file "File not found"))) | 2501 | (string-equal file "File not found")) |
| 2494 | (with-current-buffer | 2502 | ;; If the full filename is not recorded in the |
| 2495 | (find-file-noselect file 'nowarn) | 2503 | ;; breakpoint structure or in `gdb-location-alist', use |
| 2496 | (gdb-init-buffer) | 2504 | ;; -file-list-exec-source-file to extract it. |
| 2497 | ;; Only want one breakpoint icon at each location. | 2505 | (when (setq file (bindat-get-field breakpoint 'file)) |
| 2498 | (gdb-put-breakpoint-icon (string-equal flag "y") bptno | 2506 | (gdb-input (concat "list " file ":1") 'ignore) |
| 2499 | (string-to-number line))) | 2507 | (gdb-input "-file-list-exec-source-file" |
| 2500 | (gdb-input (concat "list " file ":1") 'ignore) | 2508 | `(lambda () (gdb-get-location |
| 2501 | (gdb-input "-file-list-exec-source-file" | 2509 | ,bptno ,line ,flag)))) |
| 2502 | `(lambda () (gdb-get-location | 2510 | (with-current-buffer (find-file-noselect file 'nowarn) |
| 2503 | ,bptno ,line ,flag))))))))) | 2511 | (gdb-init-buffer) |
| 2512 | ;; Only want one breakpoint icon at each location. | ||
| 2513 | (gdb-put-breakpoint-icon (string-equal flag "y") bptno | ||
| 2514 | (string-to-number line))))))))) | ||
| 2504 | 2515 | ||
| 2505 | (defvar gdb-source-file-regexp "fullname=\"\\(.*?\\)\"") | 2516 | (defvar gdb-source-file-regexp "fullname=\"\\(.*?\\)\"") |
| 2506 | 2517 | ||
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index 8912e67d603..5946e93f34d 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el | |||
| @@ -3411,7 +3411,7 @@ With arg, dereference expr if ARG is positive, otherwise do not dereference." | |||
| 3411 | (defun gud-tooltip-print-command (expr) | 3411 | (defun gud-tooltip-print-command (expr) |
| 3412 | "Return a suitable command to print the expression EXPR." | 3412 | "Return a suitable command to print the expression EXPR." |
| 3413 | (pcase gud-minor-mode | 3413 | (pcase gud-minor-mode |
| 3414 | (`gdbmi (concat "-data-evaluate-expression " expr)) | 3414 | (`gdbmi (concat "-data-evaluate-expression \"" expr "\"")) |
| 3415 | (`dbx (concat "print " expr)) | 3415 | (`dbx (concat "print " expr)) |
| 3416 | ((or `xdb `pdb) (concat "p " expr)) | 3416 | ((or `xdb `pdb) (concat "p " expr)) |
| 3417 | (`sdb (concat expr "/")))) | 3417 | (`sdb (concat expr "/")))) |
| @@ -3456,7 +3456,10 @@ This function must return nil if it doesn't handle EVENT." | |||
| 3456 | (let ((cmd (gud-tooltip-print-command expr))) | 3456 | (let ((cmd (gud-tooltip-print-command expr))) |
| 3457 | (when (and gud-tooltip-mode (eq gud-minor-mode 'gdb)) | 3457 | (when (and gud-tooltip-mode (eq gud-minor-mode 'gdb)) |
| 3458 | (gud-tooltip-mode -1) | 3458 | (gud-tooltip-mode -1) |
| 3459 | (message-box "Using GUD tooltips in this mode is unsafe\n\ | 3459 | ;; The blank before the newline is for MS-Windows, |
| 3460 | ;; whose emulation of message box removes newlines and | ||
| 3461 | ;; displays a single long line. | ||
| 3462 | (message-box "Using GUD tooltips in this mode is unsafe \n\ | ||
| 3460 | so they have been disabled.")) | 3463 | so they have been disabled.")) |
| 3461 | (unless (null cmd) ; CMD can be nil if unknown debugger | 3464 | (unless (null cmd) ; CMD can be nil if unknown debugger |
| 3462 | (if (eq gud-minor-mode 'gdbmi) | 3465 | (if (eq gud-minor-mode 'gdbmi) |
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index 848b92868e7..e13b67e596d 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el | |||
| @@ -509,7 +509,7 @@ If nil, continued arguments are aligned with the first argument." | |||
| 509 | "Non-nil means that non-block ()-, {}- and []-groups are indented as blocks. | 509 | "Non-nil means that non-block ()-, {}- and []-groups are indented as blocks. |
| 510 | The closing bracket is aligned with the line of the opening bracket, | 510 | The closing bracket is aligned with the line of the opening bracket, |
| 511 | not the contents of the brackets." | 511 | not the contents of the brackets." |
| 512 | :version "24.2" | 512 | :version "24.3" |
| 513 | :type 'boolean | 513 | :type 'boolean |
| 514 | :group 'perl) | 514 | :group 'perl) |
| 515 | 515 | ||
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e0a58d1523e..601850ed0fb 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; python.el --- Python's flying circus support for Emacs -*- coding: utf-8 -*- | 1 | ;;; python.el --- Python's flying circus support for Emacs |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2003-2012 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2003-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -50,9 +50,12 @@ | |||
| 50 | ;; `python-nav-forward-block', `python-nav-backward-block' | 50 | ;; `python-nav-forward-block', `python-nav-backward-block' |
| 51 | ;; respectively which navigate between beginning of blocks of code. | 51 | ;; respectively which navigate between beginning of blocks of code. |
| 52 | ;; Extra functions `python-nav-forward-statement', | 52 | ;; Extra functions `python-nav-forward-statement', |
| 53 | ;; `python-nav-backward-statement', `python-nav-statement-start', | 53 | ;; `python-nav-backward-statement', |
| 54 | ;; `python-nav-statement-end', `python-nav-block-start' and | 54 | ;; `python-nav-beginning-of-statement', `python-nav-end-of-statement', |
| 55 | ;; `python-nav-block-end' are included but no bound to any key. | 55 | ;; `python-nav-beginning-of-block' and `python-nav-end-of-block' are |
| 56 | ;; included but no bound to any key. At last but not least the | ||
| 57 | ;; specialized `python-nav-forward-sexp' allows easy | ||
| 58 | ;; navigation between code blocks. | ||
| 56 | 59 | ||
| 57 | ;; Shell interaction: is provided and allows you to execute easily any | 60 | ;; Shell interaction: is provided and allows you to execute easily any |
| 58 | ;; block of code of your current buffer in an inferior Python process. | 61 | ;; block of code of your current buffer in an inferior Python process. |
| @@ -247,6 +250,7 @@ | |||
| 247 | (define-key map "\C-c\C-tt" 'python-skeleton-try) | 250 | (define-key map "\C-c\C-tt" 'python-skeleton-try) |
| 248 | (define-key map "\C-c\C-tw" 'python-skeleton-while) | 251 | (define-key map "\C-c\C-tw" 'python-skeleton-while) |
| 249 | ;; Shell interaction | 252 | ;; Shell interaction |
| 253 | (define-key map "\C-c\C-p" 'run-python) | ||
| 250 | (define-key map "\C-c\C-s" 'python-shell-send-string) | 254 | (define-key map "\C-c\C-s" 'python-shell-send-string) |
| 251 | (define-key map "\C-c\C-r" 'python-shell-send-region) | 255 | (define-key map "\C-c\C-r" 'python-shell-send-region) |
| 252 | (define-key map "\C-\M-x" 'python-shell-send-defun) | 256 | (define-key map "\C-\M-x" 'python-shell-send-defun) |
| @@ -349,6 +353,40 @@ This variant of `rx' supports common python named REGEXPS." | |||
| 349 | 353 | ||
| 350 | 354 | ||
| 351 | ;;; Font-lock and syntax | 355 | ;;; Font-lock and syntax |
| 356 | |||
| 357 | (defun python-syntax-context (type &optional syntax-ppss) | ||
| 358 | "Return non-nil if point is on TYPE using SYNTAX-PPSS. | ||
| 359 | TYPE can be `comment', `string' or `paren'. It returns the start | ||
| 360 | character address of the specified TYPE." | ||
| 361 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 362 | (case type | ||
| 363 | (comment (and (nth 4 ppss) (nth 8 ppss))) | ||
| 364 | (string (and (not (nth 4 ppss)) (nth 8 ppss))) | ||
| 365 | (paren (nth 1 ppss)) | ||
| 366 | (t nil)))) | ||
| 367 | |||
| 368 | (defun python-syntax-context-type (&optional syntax-ppss) | ||
| 369 | "Return the context type using SYNTAX-PPSS. | ||
| 370 | The type returned can be `comment', `string' or `paren'." | ||
| 371 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 372 | (cond | ||
| 373 | ((nth 8 ppss) (if (nth 4 ppss) 'comment 'string)) | ||
| 374 | ((nth 1 ppss) 'paren)))) | ||
| 375 | |||
| 376 | (defsubst python-syntax-comment-or-string-p () | ||
| 377 | "Return non-nil if point is inside 'comment or 'string." | ||
| 378 | (nth 8 (syntax-ppss))) | ||
| 379 | |||
| 380 | (define-obsolete-function-alias | ||
| 381 | 'python-info-ppss-context #'python-syntax-context "24.3") | ||
| 382 | |||
| 383 | (define-obsolete-function-alias | ||
| 384 | 'python-info-ppss-context-type #'python-syntax-context-type "24.3") | ||
| 385 | |||
| 386 | (define-obsolete-function-alias | ||
| 387 | 'python-info-ppss-comment-or-string-p | ||
| 388 | #'python-syntax-comment-or-string-p "24.3") | ||
| 389 | |||
| 352 | (defvar python-font-lock-keywords | 390 | (defvar python-font-lock-keywords |
| 353 | ;; Keywords | 391 | ;; Keywords |
| 354 | `(,(rx symbol-start | 392 | `(,(rx symbol-start |
| @@ -435,9 +473,9 @@ This variant of `rx' supports common python named REGEXPS." | |||
| 435 | (? ?\[ (+ (not (any ?\]))) ?\]) (* space) | 473 | (? ?\[ (+ (not (any ?\]))) ?\]) (* space) |
| 436 | assignment-operator))) | 474 | assignment-operator))) |
| 437 | (when (re-search-forward re limit t) | 475 | (when (re-search-forward re limit t) |
| 438 | (while (and (python-info-ppss-context 'paren) | 476 | (while (and (python-syntax-context 'paren) |
| 439 | (re-search-forward re limit t))) | 477 | (re-search-forward re limit t))) |
| 440 | (if (and (not (python-info-ppss-context 'paren)) | 478 | (if (and (not (python-syntax-context 'paren)) |
| 441 | (not (equal (char-after (point-marker)) ?=))) | 479 | (not (equal (char-after (point-marker)) ?=))) |
| 442 | t | 480 | t |
| 443 | (set-match-data nil))))) | 481 | (set-match-data nil))))) |
| @@ -450,10 +488,10 @@ This variant of `rx' supports common python named REGEXPS." | |||
| 450 | assignment-operator))) | 488 | assignment-operator))) |
| 451 | (when (and (re-search-forward re limit t) | 489 | (when (and (re-search-forward re limit t) |
| 452 | (goto-char (nth 3 (match-data)))) | 490 | (goto-char (nth 3 (match-data)))) |
| 453 | (while (and (python-info-ppss-context 'paren) | 491 | (while (and (python-syntax-context 'paren) |
| 454 | (re-search-forward re limit t)) | 492 | (re-search-forward re limit t)) |
| 455 | (goto-char (nth 3 (match-data)))) | 493 | (goto-char (nth 3 (match-data)))) |
| 456 | (if (not (python-info-ppss-context 'paren)) | 494 | (if (not (python-syntax-context 'paren)) |
| 457 | t | 495 | t |
| 458 | (set-match-data nil))))) | 496 | (set-match-data nil))))) |
| 459 | (1 font-lock-variable-name-face nil nil)))) | 497 | (1 font-lock-variable-name-face nil nil)))) |
| @@ -550,10 +588,10 @@ It makes underscores and dots word constituent chars.") | |||
| 550 | :safe 'booleanp) | 588 | :safe 'booleanp) |
| 551 | 589 | ||
| 552 | (define-obsolete-variable-alias | 590 | (define-obsolete-variable-alias |
| 553 | 'python-indent 'python-indent-offset "24.2") | 591 | 'python-indent 'python-indent-offset "24.3") |
| 554 | 592 | ||
| 555 | (define-obsolete-variable-alias | 593 | (define-obsolete-variable-alias |
| 556 | 'python-guess-indent 'python-indent-guess-indent-offset "24.2") | 594 | 'python-guess-indent 'python-indent-guess-indent-offset "24.3") |
| 557 | 595 | ||
| 558 | (defvar python-indent-current-level 0 | 596 | (defvar python-indent-current-level 0 |
| 559 | "Current indentation level `python-indent-line-function' is using.") | 597 | "Current indentation level `python-indent-line-function' is using.") |
| @@ -578,7 +616,7 @@ These make `python-indent-calculate-indentation' subtract the value of | |||
| 578 | (re-search-forward | 616 | (re-search-forward |
| 579 | (python-rx line-start block-start) nil t)) | 617 | (python-rx line-start block-start) nil t)) |
| 580 | (when (and | 618 | (when (and |
| 581 | (not (python-info-ppss-context-type)) | 619 | (not (python-syntax-context-type)) |
| 582 | (progn | 620 | (progn |
| 583 | (goto-char (line-end-position)) | 621 | (goto-char (line-end-position)) |
| 584 | (python-util-forward-comment -1) | 622 | (python-util-forward-comment -1) |
| @@ -628,14 +666,14 @@ START is the buffer position where the sexp starts." | |||
| 628 | (bobp)) | 666 | (bobp)) |
| 629 | 'no-indent) | 667 | 'no-indent) |
| 630 | ;; Inside a paren | 668 | ;; Inside a paren |
| 631 | ((setq start (python-info-ppss-context 'paren ppss)) | 669 | ((setq start (python-syntax-context 'paren ppss)) |
| 632 | 'inside-paren) | 670 | 'inside-paren) |
| 633 | ;; Inside string | 671 | ;; Inside string |
| 634 | ((setq start (python-info-ppss-context 'string ppss)) | 672 | ((setq start (python-syntax-context 'string ppss)) |
| 635 | 'inside-string) | 673 | 'inside-string) |
| 636 | ;; After backslash | 674 | ;; After backslash |
| 637 | ((setq start (when (not (or (python-info-ppss-context 'string ppss) | 675 | ((setq start (when (not (or (python-syntax-context 'string ppss) |
| 638 | (python-info-ppss-context 'comment ppss))) | 676 | (python-syntax-context 'comment ppss))) |
| 639 | (let ((line-beg-pos (line-beginning-position))) | 677 | (let ((line-beg-pos (line-beginning-position))) |
| 640 | (when (python-info-line-ends-backslash-p | 678 | (when (python-info-line-ends-backslash-p |
| 641 | (1- line-beg-pos)) | 679 | (1- line-beg-pos)) |
| @@ -653,9 +691,7 @@ START is the buffer position where the sexp starts." | |||
| 653 | (while (and (re-search-backward | 691 | (while (and (re-search-backward |
| 654 | (python-rx block-start) nil t) | 692 | (python-rx block-start) nil t) |
| 655 | (or | 693 | (or |
| 656 | (python-info-ppss-context 'string) | 694 | (python-syntax-context-type) |
| 657 | (python-info-ppss-context 'comment) | ||
| 658 | (python-info-ppss-context 'paren) | ||
| 659 | (python-info-continuation-line-p)))) | 695 | (python-info-continuation-line-p)))) |
| 660 | (when (looking-at (python-rx block-start)) | 696 | (when (looking-at (python-rx block-start)) |
| 661 | (point-marker))))) | 697 | (point-marker))))) |
| @@ -664,7 +700,7 @@ START is the buffer position where the sexp starts." | |||
| 664 | ((setq start (save-excursion | 700 | ((setq start (save-excursion |
| 665 | (back-to-indentation) | 701 | (back-to-indentation) |
| 666 | (python-util-forward-comment -1) | 702 | (python-util-forward-comment -1) |
| 667 | (python-nav-statement-start) | 703 | (python-nav-beginning-of-statement) |
| 668 | (point-marker))) | 704 | (point-marker))) |
| 669 | 'after-line) | 705 | 'after-line) |
| 670 | ;; Do not indent | 706 | ;; Do not indent |
| @@ -719,17 +755,13 @@ START is the buffer position where the sexp starts." | |||
| 719 | (while (prog2 | 755 | (while (prog2 |
| 720 | (forward-line -1) | 756 | (forward-line -1) |
| 721 | (and (not (bobp)) | 757 | (and (not (bobp)) |
| 722 | (python-info-ppss-context 'paren)))) | 758 | (python-syntax-context 'paren)))) |
| 723 | (goto-char (line-end-position)) | 759 | (goto-char (line-end-position)) |
| 724 | (while (and (re-search-backward | 760 | (while (and (re-search-backward |
| 725 | "\\." (line-beginning-position) t) | 761 | "\\." (line-beginning-position) t) |
| 726 | (or (python-info-ppss-context 'comment) | 762 | (python-syntax-context-type))) |
| 727 | (python-info-ppss-context 'string) | ||
| 728 | (python-info-ppss-context 'paren)))) | ||
| 729 | (if (and (looking-at "\\.") | 763 | (if (and (looking-at "\\.") |
| 730 | (not (or (python-info-ppss-context 'comment) | 764 | (not (python-syntax-context-type))) |
| 731 | (python-info-ppss-context 'string) | ||
| 732 | (python-info-ppss-context 'paren)))) | ||
| 733 | ;; The indentation is the same column of the | 765 | ;; The indentation is the same column of the |
| 734 | ;; first matching dot that's not inside a | 766 | ;; first matching dot that's not inside a |
| 735 | ;; comment, a string or a paren | 767 | ;; comment, a string or a paren |
| @@ -785,7 +817,7 @@ START is the buffer position where the sexp starts." | |||
| 785 | (when (and (looking-at (regexp-opt '(")" "]" "}"))) | 817 | (when (and (looking-at (regexp-opt '(")" "]" "}"))) |
| 786 | (progn | 818 | (progn |
| 787 | (forward-char 1) | 819 | (forward-char 1) |
| 788 | (not (python-info-ppss-context 'paren)))) | 820 | (not (python-syntax-context 'paren)))) |
| 789 | (goto-char context-start) | 821 | (goto-char context-start) |
| 790 | (current-indentation)))) | 822 | (current-indentation)))) |
| 791 | ;; If open paren is contained on a line by itself add another | 823 | ;; If open paren is contained on a line by itself add another |
| @@ -885,8 +917,7 @@ See `python-indent-line' for details." | |||
| 885 | (defun python-indent-dedent-line () | 917 | (defun python-indent-dedent-line () |
| 886 | "De-indent current line." | 918 | "De-indent current line." |
| 887 | (interactive "*") | 919 | (interactive "*") |
| 888 | (when (and (not (or (python-info-ppss-context 'string) | 920 | (when (and (not (python-syntax-comment-or-string-p)) |
| 889 | (python-info-ppss-context 'comment))) | ||
| 890 | (<= (point-marker) (save-excursion | 921 | (<= (point-marker) (save-excursion |
| 891 | (back-to-indentation) | 922 | (back-to-indentation) |
| 892 | (point-marker))) | 923 | (point-marker))) |
| @@ -977,8 +1008,7 @@ With numeric ARG, just insert that many colons. With | |||
| 977 | (when (and (not arg) | 1008 | (when (and (not arg) |
| 978 | (eolp) | 1009 | (eolp) |
| 979 | (not (equal ?: (char-after (- (point-marker) 2)))) | 1010 | (not (equal ?: (char-after (- (point-marker) 2)))) |
| 980 | (not (or (python-info-ppss-context 'string) | 1011 | (not (python-syntax-comment-or-string-p))) |
| 981 | (python-info-ppss-context 'comment)))) | ||
| 982 | (let ((indentation (current-indentation)) | 1012 | (let ((indentation (current-indentation)) |
| 983 | (calculated-indentation (python-indent-calculate-indentation))) | 1013 | (calculated-indentation (python-indent-calculate-indentation))) |
| 984 | (python-info-closing-block-message) | 1014 | (python-info-closing-block-message) |
| @@ -1002,7 +1032,7 @@ automatically if needed." | |||
| 1002 | (goto-char (line-beginning-position)) | 1032 | (goto-char (line-beginning-position)) |
| 1003 | ;; If after going to the beginning of line the point | 1033 | ;; If after going to the beginning of line the point |
| 1004 | ;; is still inside a paren it's ok to do the trick | 1034 | ;; is still inside a paren it's ok to do the trick |
| 1005 | (when (python-info-ppss-context 'paren) | 1035 | (when (python-syntax-context 'paren) |
| 1006 | (let ((indentation (python-indent-calculate-indentation))) | 1036 | (let ((indentation (python-indent-calculate-indentation))) |
| 1007 | (when (< (current-indentation) indentation) | 1037 | (when (< (current-indentation) indentation) |
| 1008 | (indent-line-to indentation))))))) | 1038 | (indent-line-to indentation))))))) |
| @@ -1036,7 +1066,7 @@ non-nil if point is moved to `beginning-of-defun'." | |||
| 1036 | (end-of-line 1)) | 1066 | (end-of-line 1)) |
| 1037 | (while (and (funcall re-search-fn | 1067 | (while (and (funcall re-search-fn |
| 1038 | python-nav-beginning-of-defun-regexp nil t) | 1068 | python-nav-beginning-of-defun-regexp nil t) |
| 1039 | (python-info-ppss-context-type))) | 1069 | (python-syntax-context-type))) |
| 1040 | (and (python-info-looking-at-beginning-of-defun) | 1070 | (and (python-info-looking-at-beginning-of-defun) |
| 1041 | (or (not (= (line-number-at-pos pos) | 1071 | (or (not (= (line-number-at-pos pos) |
| 1042 | (line-number-at-pos))) | 1072 | (line-number-at-pos))) |
| @@ -1086,18 +1116,18 @@ Returns nil if point is not in a def or class." | |||
| 1086 | (equal (char-after (+ (point) (current-indentation))) ?#) | 1116 | (equal (char-after (+ (point) (current-indentation))) ?#) |
| 1087 | (<= (current-indentation) beg-defun-indent) | 1117 | (<= (current-indentation) beg-defun-indent) |
| 1088 | (looking-at (python-rx decorator)) | 1118 | (looking-at (python-rx decorator)) |
| 1089 | (python-info-ppss-context-type)))) | 1119 | (python-syntax-context-type)))) |
| 1090 | (forward-line 1) | 1120 | (forward-line 1) |
| 1091 | ;; If point falls inside a paren or string context the point is | 1121 | ;; If point falls inside a paren or string context the point is |
| 1092 | ;; forwarded at the end of it (or end of buffer if its not closed) | 1122 | ;; forwarded at the end of it (or end of buffer if its not closed) |
| 1093 | (let ((context-type (python-info-ppss-context-type))) | 1123 | (let ((context-type (python-syntax-context-type))) |
| 1094 | (when (memq context-type '(paren string)) | 1124 | (when (memq context-type '(paren string)) |
| 1095 | ;; Slow but safe. | 1125 | ;; Slow but safe. |
| 1096 | (while (and (not (eobp)) | 1126 | (while (and (not (eobp)) |
| 1097 | (python-info-ppss-context-type)) | 1127 | (python-syntax-context-type)) |
| 1098 | (forward-line 1))))))) | 1128 | (forward-line 1))))))) |
| 1099 | 1129 | ||
| 1100 | (defun python-nav-statement-start () | 1130 | (defun python-nav-beginning-of-statement () |
| 1101 | "Move to start of current statement." | 1131 | "Move to start of current statement." |
| 1102 | (interactive "^") | 1132 | (interactive "^") |
| 1103 | (while (and (or (back-to-indentation) t) | 1133 | (while (and (or (back-to-indentation) t) |
| @@ -1106,19 +1136,19 @@ Returns nil if point is not in a def or class." | |||
| 1106 | (save-excursion | 1136 | (save-excursion |
| 1107 | (forward-line -1) | 1137 | (forward-line -1) |
| 1108 | (python-info-line-ends-backslash-p)) | 1138 | (python-info-line-ends-backslash-p)) |
| 1109 | (python-info-ppss-context 'string) | 1139 | (python-syntax-context 'string) |
| 1110 | (python-info-ppss-context 'paren)) | 1140 | (python-syntax-context 'paren)) |
| 1111 | (forward-line -1))))) | 1141 | (forward-line -1))))) |
| 1112 | 1142 | ||
| 1113 | (defun python-nav-statement-end () | 1143 | (defun python-nav-end-of-statement () |
| 1114 | "Move to end of current statement." | 1144 | "Move to end of current statement." |
| 1115 | (interactive "^") | 1145 | (interactive "^") |
| 1116 | (while (and (goto-char (line-end-position)) | 1146 | (while (and (goto-char (line-end-position)) |
| 1117 | (not (eobp)) | 1147 | (not (eobp)) |
| 1118 | (when (or | 1148 | (when (or |
| 1119 | (python-info-line-ends-backslash-p) | 1149 | (python-info-line-ends-backslash-p) |
| 1120 | (python-info-ppss-context 'string) | 1150 | (python-syntax-context 'string) |
| 1121 | (python-info-ppss-context 'paren)) | 1151 | (python-syntax-context 'paren)) |
| 1122 | (forward-line 1))))) | 1152 | (forward-line 1))))) |
| 1123 | 1153 | ||
| 1124 | (defun python-nav-backward-statement (&optional arg) | 1154 | (defun python-nav-backward-statement (&optional arg) |
| @@ -1135,29 +1165,29 @@ backward to previous statement." | |||
| 1135 | (interactive "^p") | 1165 | (interactive "^p") |
| 1136 | (or arg (setq arg 1)) | 1166 | (or arg (setq arg 1)) |
| 1137 | (while (> arg 0) | 1167 | (while (> arg 0) |
| 1138 | (python-nav-statement-end) | 1168 | (python-nav-end-of-statement) |
| 1139 | (python-util-forward-comment) | 1169 | (python-util-forward-comment) |
| 1140 | (python-nav-statement-start) | 1170 | (python-nav-beginning-of-statement) |
| 1141 | (setq arg (1- arg))) | 1171 | (setq arg (1- arg))) |
| 1142 | (while (< arg 0) | 1172 | (while (< arg 0) |
| 1143 | (python-nav-statement-start) | 1173 | (python-nav-beginning-of-statement) |
| 1144 | (python-util-forward-comment -1) | 1174 | (python-util-forward-comment -1) |
| 1145 | (python-nav-statement-start) | 1175 | (python-nav-beginning-of-statement) |
| 1146 | (setq arg (1+ arg)))) | 1176 | (setq arg (1+ arg)))) |
| 1147 | 1177 | ||
| 1148 | (defun python-nav-block-start () | 1178 | (defun python-nav-beginning-of-block () |
| 1149 | "Move to start of current block." | 1179 | "Move to start of current block." |
| 1150 | (interactive "^") | 1180 | (interactive "^") |
| 1151 | (let ((starting-pos (point)) | 1181 | (let ((starting-pos (point)) |
| 1152 | (block-regexp (python-rx | 1182 | (block-regexp (python-rx |
| 1153 | line-start (* whitespace) block-start))) | 1183 | line-start (* whitespace) block-start))) |
| 1154 | (if (progn | 1184 | (if (progn |
| 1155 | (python-nav-statement-start) | 1185 | (python-nav-beginning-of-statement) |
| 1156 | (looking-at (python-rx block-start))) | 1186 | (looking-at (python-rx block-start))) |
| 1157 | (point-marker) | 1187 | (point-marker) |
| 1158 | ;; Go to first line beginning a statement | 1188 | ;; Go to first line beginning a statement |
| 1159 | (while (and (not (bobp)) | 1189 | (while (and (not (bobp)) |
| 1160 | (or (and (python-nav-statement-start) nil) | 1190 | (or (and (python-nav-beginning-of-statement) nil) |
| 1161 | (python-info-current-line-comment-p) | 1191 | (python-info-current-line-comment-p) |
| 1162 | (python-info-current-line-empty-p))) | 1192 | (python-info-current-line-empty-p))) |
| 1163 | (forward-line -1)) | 1193 | (forward-line -1)) |
| @@ -1171,16 +1201,16 @@ backward to previous statement." | |||
| 1171 | (point-marker) | 1201 | (point-marker) |
| 1172 | (and (goto-char starting-pos) nil)))))) | 1202 | (and (goto-char starting-pos) nil)))))) |
| 1173 | 1203 | ||
| 1174 | (defun python-nav-block-end () | 1204 | (defun python-nav-end-of-block () |
| 1175 | "Move to end of current block." | 1205 | "Move to end of current block." |
| 1176 | (interactive "^") | 1206 | (interactive "^") |
| 1177 | (when (python-nav-block-start) | 1207 | (when (python-nav-beginning-of-block) |
| 1178 | (let ((block-indentation (current-indentation))) | 1208 | (let ((block-indentation (current-indentation))) |
| 1179 | (python-nav-statement-end) | 1209 | (python-nav-end-of-statement) |
| 1180 | (while (and (forward-line 1) | 1210 | (while (and (forward-line 1) |
| 1181 | (not (eobp)) | 1211 | (not (eobp)) |
| 1182 | (or (and (> (current-indentation) block-indentation) | 1212 | (or (and (> (current-indentation) block-indentation) |
| 1183 | (or (python-nav-statement-end) t)) | 1213 | (or (python-nav-end-of-statement) t)) |
| 1184 | (python-info-current-line-comment-p) | 1214 | (python-info-current-line-comment-p) |
| 1185 | (python-info-current-line-empty-p)))) | 1215 | (python-info-current-line-empty-p)))) |
| 1186 | (python-util-forward-comment -1) | 1216 | (python-util-forward-comment -1) |
| @@ -1203,103 +1233,194 @@ backward to previous block." | |||
| 1203 | (python-rx line-start (* whitespace) block-start)) | 1233 | (python-rx line-start (* whitespace) block-start)) |
| 1204 | (starting-pos (point))) | 1234 | (starting-pos (point))) |
| 1205 | (while (> arg 0) | 1235 | (while (> arg 0) |
| 1206 | (python-nav-statement-end) | 1236 | (python-nav-end-of-statement) |
| 1207 | (while (and | 1237 | (while (and |
| 1208 | (re-search-forward block-start-regexp nil t) | 1238 | (re-search-forward block-start-regexp nil t) |
| 1209 | (or (python-info-ppss-context 'string) | 1239 | (python-syntax-context-type))) |
| 1210 | (python-info-ppss-context 'comment) | ||
| 1211 | (python-info-ppss-context 'paren)))) | ||
| 1212 | (setq arg (1- arg))) | 1240 | (setq arg (1- arg))) |
| 1213 | (while (< arg 0) | 1241 | (while (< arg 0) |
| 1214 | (python-nav-statement-start) | 1242 | (python-nav-beginning-of-statement) |
| 1215 | (while (and | 1243 | (while (and |
| 1216 | (re-search-backward block-start-regexp nil t) | 1244 | (re-search-backward block-start-regexp nil t) |
| 1217 | (or (python-info-ppss-context 'string) | 1245 | (python-syntax-context-type))) |
| 1218 | (python-info-ppss-context 'comment) | ||
| 1219 | (python-info-ppss-context 'paren)))) | ||
| 1220 | (setq arg (1+ arg))) | 1246 | (setq arg (1+ arg))) |
| 1221 | (python-nav-statement-start) | 1247 | (python-nav-beginning-of-statement) |
| 1222 | (if (not (looking-at (python-rx block-start))) | 1248 | (if (not (looking-at (python-rx block-start))) |
| 1223 | (and (goto-char starting-pos) nil) | 1249 | (and (goto-char starting-pos) nil) |
| 1224 | (and (not (= (point) starting-pos)) (point-marker))))) | 1250 | (and (not (= (point) starting-pos)) (point-marker))))) |
| 1225 | 1251 | ||
| 1226 | (defun python-nav-forward-sexp-function (&optional arg) | 1252 | (defun python-nav-lisp-forward-sexp-safe (&optional arg) |
| 1253 | "Safe version of standard `forward-sexp'. | ||
| 1254 | When ARG > 0 move forward, else if ARG is < 0." | ||
| 1255 | (or arg (setq arg 1)) | ||
| 1256 | (let ((forward-sexp-function nil) | ||
| 1257 | (paren-regexp | ||
| 1258 | (if (> arg 0) (python-rx close-paren) (python-rx open-paren))) | ||
| 1259 | (search-fn | ||
| 1260 | (if (> arg 0) #'re-search-forward #'re-search-backward))) | ||
| 1261 | (condition-case nil | ||
| 1262 | (forward-sexp arg) | ||
| 1263 | (error | ||
| 1264 | (while (and (funcall search-fn paren-regexp nil t) | ||
| 1265 | (python-syntax-context 'paren))))))) | ||
| 1266 | |||
| 1267 | (defun python-nav--forward-sexp () | ||
| 1268 | "Move to forward sexp." | ||
| 1269 | (case (python-syntax-context-type) | ||
| 1270 | (string | ||
| 1271 | ;; Inside of a string, get out of it. | ||
| 1272 | (while (and (re-search-forward "[\"']" nil t) | ||
| 1273 | (python-syntax-context 'string)))) | ||
| 1274 | (comment | ||
| 1275 | ;; Inside of a comment, just move forward. | ||
| 1276 | (python-util-forward-comment)) | ||
| 1277 | (paren | ||
| 1278 | (python-nav-lisp-forward-sexp-safe 1)) | ||
| 1279 | (t | ||
| 1280 | (if (and (not (eobp)) | ||
| 1281 | (= (syntax-class (syntax-after (point))) 4)) | ||
| 1282 | ;; Looking an open-paren | ||
| 1283 | (python-nav-lisp-forward-sexp-safe 1) | ||
| 1284 | (let ((block-starting-pos | ||
| 1285 | (save-excursion (python-nav-beginning-of-block))) | ||
| 1286 | (block-ending-pos | ||
| 1287 | (save-excursion (python-nav-end-of-block))) | ||
| 1288 | (next-block-starting-pos | ||
| 1289 | (save-excursion (python-nav-forward-block)))) | ||
| 1290 | (cond | ||
| 1291 | ((not block-starting-pos) | ||
| 1292 | ;; Not inside a block, move to closest one. | ||
| 1293 | (and next-block-starting-pos | ||
| 1294 | (goto-char next-block-starting-pos))) | ||
| 1295 | ((= (point) block-starting-pos) | ||
| 1296 | ;; Point is at beginning of block | ||
| 1297 | (if (and next-block-starting-pos | ||
| 1298 | (< next-block-starting-pos block-ending-pos)) | ||
| 1299 | ;; Beginning of next block is closer than current's | ||
| 1300 | ;; end, move to it. | ||
| 1301 | (goto-char next-block-starting-pos) | ||
| 1302 | (goto-char block-ending-pos))) | ||
| 1303 | ((= block-ending-pos (point)) | ||
| 1304 | ;; Point is at end of current block | ||
| 1305 | (let ((parent-block-end-pos | ||
| 1306 | (save-excursion | ||
| 1307 | (python-util-forward-comment) | ||
| 1308 | (python-nav-beginning-of-block) | ||
| 1309 | (python-nav-end-of-block)))) | ||
| 1310 | (if (and parent-block-end-pos | ||
| 1311 | (or (not next-block-starting-pos) | ||
| 1312 | (> next-block-starting-pos parent-block-end-pos))) | ||
| 1313 | ;; If the parent block ends before next block | ||
| 1314 | ;; starts move to it. | ||
| 1315 | (goto-char parent-block-end-pos) | ||
| 1316 | (and next-block-starting-pos | ||
| 1317 | (goto-char next-block-starting-pos))))) | ||
| 1318 | (t (python-nav-end-of-block)))))))) | ||
| 1319 | |||
| 1320 | (defun python-nav--backward-sexp () | ||
| 1321 | "Move to backward sexp." | ||
| 1322 | (case (python-syntax-context-type) | ||
| 1323 | (string | ||
| 1324 | ;; Inside of a string, get out of it. | ||
| 1325 | (while (and (re-search-backward "[\"']" nil t) | ||
| 1326 | (python-syntax-context 'string)))) | ||
| 1327 | (comment | ||
| 1328 | ;; Inside of a comment, just move backward. | ||
| 1329 | (python-util-forward-comment -1)) | ||
| 1330 | (paren | ||
| 1331 | ;; Handle parens like we are lisp. | ||
| 1332 | (python-nav-lisp-forward-sexp-safe -1)) | ||
| 1333 | (t | ||
| 1334 | (let* ((block-starting-pos | ||
| 1335 | (save-excursion (python-nav-beginning-of-block))) | ||
| 1336 | (block-ending-pos | ||
| 1337 | (save-excursion (python-nav-end-of-block))) | ||
| 1338 | (prev-block-ending-pos | ||
| 1339 | (save-excursion (when (python-nav-backward-block) | ||
| 1340 | (python-nav-end-of-block)))) | ||
| 1341 | (prev-block-parent-ending-pos | ||
| 1342 | (save-excursion | ||
| 1343 | (when prev-block-ending-pos | ||
| 1344 | (goto-char prev-block-ending-pos) | ||
| 1345 | (python-util-forward-comment) | ||
| 1346 | (python-nav-beginning-of-block) | ||
| 1347 | (python-nav-end-of-block))))) | ||
| 1348 | (if (and (not (bobp)) | ||
| 1349 | (= (syntax-class (syntax-after (1- (point)))) 5)) | ||
| 1350 | ;; Char before point is a paren closing char, handle it | ||
| 1351 | ;; like we are lisp. | ||
| 1352 | (python-nav-lisp-forward-sexp-safe -1) | ||
| 1353 | (cond | ||
| 1354 | ((not block-ending-pos) | ||
| 1355 | ;; Not in and ending pos, move to end of previous block. | ||
| 1356 | (and (python-nav-backward-block) | ||
| 1357 | (python-nav-end-of-block))) | ||
| 1358 | ((= (point) block-ending-pos) | ||
| 1359 | ;; In ending pos, we need to search backwards for the | ||
| 1360 | ;; closest point looking the list of candidates from here. | ||
| 1361 | (let ((candidates)) | ||
| 1362 | (dolist (name | ||
| 1363 | '(prev-block-parent-ending-pos | ||
| 1364 | prev-block-ending-pos | ||
| 1365 | block-ending-pos | ||
| 1366 | block-starting-pos)) | ||
| 1367 | (when (and (symbol-value name) | ||
| 1368 | (< (symbol-value name) (point))) | ||
| 1369 | (add-to-list 'candidates (symbol-value name)))) | ||
| 1370 | (goto-char (apply 'max candidates)))) | ||
| 1371 | ((> (point) block-ending-pos) | ||
| 1372 | ;; After an ending position, move to it. | ||
| 1373 | (goto-char block-ending-pos)) | ||
| 1374 | ((= (point) block-starting-pos) | ||
| 1375 | ;; On a block starting position. | ||
| 1376 | (if (not (> (point) (or prev-block-ending-pos (point)))) | ||
| 1377 | ;; Point is after the end position of the block that | ||
| 1378 | ;; wraps the current one, just move a block backward. | ||
| 1379 | (python-nav-backward-block) | ||
| 1380 | ;; If we got here we are facing a case like this one: | ||
| 1381 | ;; | ||
| 1382 | ;; try: | ||
| 1383 | ;; return here() | ||
| 1384 | ;; except Exception as e: | ||
| 1385 | ;; | ||
| 1386 | ;; Where point is on the "except" and must move to the | ||
| 1387 | ;; end of "here()". | ||
| 1388 | (goto-char prev-block-ending-pos) | ||
| 1389 | (let ((parent-block-ending-pos | ||
| 1390 | (save-excursion | ||
| 1391 | (python-nav-forward-sexp) | ||
| 1392 | (and (not (looking-at (python-rx block-start))) | ||
| 1393 | (point))))) | ||
| 1394 | (when (and parent-block-ending-pos | ||
| 1395 | (> parent-block-ending-pos prev-block-ending-pos)) | ||
| 1396 | ;; If we got here we are facing a case like this one: | ||
| 1397 | ;; | ||
| 1398 | ;; except ImportError: | ||
| 1399 | ;; if predicate(): | ||
| 1400 | ;; processing() | ||
| 1401 | ;; here() | ||
| 1402 | ;; except AttributeError: | ||
| 1403 | ;; | ||
| 1404 | ;; Where point is on the "except" and must move to | ||
| 1405 | ;; the end of "here()". Without this extra step we'd | ||
| 1406 | ;; just get to the end of processing(). | ||
| 1407 | (goto-char parent-block-ending-pos))))) | ||
| 1408 | (t | ||
| 1409 | (if (and prev-block-ending-pos (< prev-block-ending-pos (point))) | ||
| 1410 | (goto-char prev-block-ending-pos) | ||
| 1411 | (python-nav-beginning-of-block))))))))) | ||
| 1412 | |||
| 1413 | (defun python-nav-forward-sexp (&optional arg) | ||
| 1227 | "Move forward across one block of code. | 1414 | "Move forward across one block of code. |
| 1228 | With ARG, do it that many times. Negative arg -N means | 1415 | With ARG, do it that many times. Negative arg -N means |
| 1229 | move backward N times." | 1416 | move backward N times." |
| 1230 | (interactive "^p") | 1417 | (interactive "^p") |
| 1231 | (or arg (setq arg 1)) | 1418 | (or arg (setq arg 1)) |
| 1232 | (while (> arg 0) | 1419 | (while (> arg 0) |
| 1233 | (let ((block-starting-pos | 1420 | (python-nav--forward-sexp) |
| 1234 | (save-excursion (python-nav-block-start))) | 1421 | (setq arg (1- arg))) |
| 1235 | (block-ending-pos | ||
| 1236 | (save-excursion (python-nav-block-end))) | ||
| 1237 | (next-block-starting-pos | ||
| 1238 | (save-excursion (python-nav-forward-block)))) | ||
| 1239 | (cond ((not block-starting-pos) | ||
| 1240 | (python-nav-forward-block)) | ||
| 1241 | ((= (point) block-starting-pos) | ||
| 1242 | (if (or (not next-block-starting-pos) | ||
| 1243 | (< block-ending-pos next-block-starting-pos)) | ||
| 1244 | (python-nav-block-end) | ||
| 1245 | (python-nav-forward-block))) | ||
| 1246 | ((= block-ending-pos (point)) | ||
| 1247 | (let ((parent-block-end-pos | ||
| 1248 | (save-excursion | ||
| 1249 | (python-util-forward-comment) | ||
| 1250 | (python-nav-block-start) | ||
| 1251 | (python-nav-block-end)))) | ||
| 1252 | (if (and parent-block-end-pos | ||
| 1253 | (or (not next-block-starting-pos) | ||
| 1254 | (> next-block-starting-pos parent-block-end-pos))) | ||
| 1255 | (goto-char parent-block-end-pos) | ||
| 1256 | (python-nav-forward-block)))) | ||
| 1257 | (t (python-nav-block-end)))) | ||
| 1258 | (setq arg (1- arg))) | ||
| 1259 | (while (< arg 0) | 1422 | (while (< arg 0) |
| 1260 | (let* ((block-starting-pos | 1423 | (python-nav--backward-sexp) |
| 1261 | (save-excursion (python-nav-block-start))) | ||
| 1262 | (block-ending-pos | ||
| 1263 | (save-excursion (python-nav-block-end))) | ||
| 1264 | (prev-block-ending-pos | ||
| 1265 | (save-excursion (when (python-nav-backward-block) | ||
| 1266 | (python-nav-block-end)))) | ||
| 1267 | (prev-block-parent-ending-pos | ||
| 1268 | (save-excursion | ||
| 1269 | (when prev-block-ending-pos | ||
| 1270 | (goto-char prev-block-ending-pos) | ||
| 1271 | (python-util-forward-comment) | ||
| 1272 | (python-nav-block-start) | ||
| 1273 | (python-nav-block-end))))) | ||
| 1274 | (cond ((not block-ending-pos) | ||
| 1275 | (and (python-nav-backward-block) | ||
| 1276 | (python-nav-block-end))) | ||
| 1277 | ((= (point) block-ending-pos) | ||
| 1278 | (let ((candidates)) | ||
| 1279 | (dolist (name | ||
| 1280 | '(prev-block-parent-ending-pos | ||
| 1281 | prev-block-ending-pos | ||
| 1282 | block-ending-pos | ||
| 1283 | block-starting-pos)) | ||
| 1284 | (when (and (symbol-value name) | ||
| 1285 | (< (symbol-value name) (point))) | ||
| 1286 | (add-to-list 'candidates (symbol-value name)))) | ||
| 1287 | (goto-char (apply 'max candidates)))) | ||
| 1288 | ((> (point) block-ending-pos) | ||
| 1289 | (python-nav-block-end)) | ||
| 1290 | ((= (point) block-starting-pos) | ||
| 1291 | (if (not (> (point) (or prev-block-ending-pos (point)))) | ||
| 1292 | (python-nav-backward-block) | ||
| 1293 | (goto-char prev-block-ending-pos) | ||
| 1294 | (let ((parent-block-ending-pos | ||
| 1295 | (save-excursion | ||
| 1296 | (python-nav-forward-sexp-function) | ||
| 1297 | (and (not (looking-at (python-rx block-start))) | ||
| 1298 | (point))))) | ||
| 1299 | (when (and parent-block-ending-pos | ||
| 1300 | (> parent-block-ending-pos prev-block-ending-pos)) | ||
| 1301 | (goto-char parent-block-ending-pos))))) | ||
| 1302 | (t (python-nav-block-start)))) | ||
| 1303 | (setq arg (1+ arg)))) | 1424 | (setq arg (1+ arg)))) |
| 1304 | 1425 | ||
| 1305 | 1426 | ||
| @@ -1362,14 +1483,6 @@ Restart the python shell after changing this variable for it to take effect." | |||
| 1362 | :group 'python | 1483 | :group 'python |
| 1363 | :safe 'booleanp) | 1484 | :safe 'booleanp) |
| 1364 | 1485 | ||
| 1365 | (defcustom python-shell-send-setup-max-wait 5 | ||
| 1366 | "Seconds to wait for process output before code setup. | ||
| 1367 | If output is received before the specified time then control is | ||
| 1368 | returned in that moment and not after waiting." | ||
| 1369 | :type 'integer | ||
| 1370 | :group 'python | ||
| 1371 | :safe 'integerp) | ||
| 1372 | |||
| 1373 | (defcustom python-shell-process-environment nil | 1486 | (defcustom python-shell-process-environment nil |
| 1374 | "List of environment variables for Python shell. | 1487 | "List of environment variables for Python shell. |
| 1375 | This variable follows the same rules as `process-environment' | 1488 | This variable follows the same rules as `process-environment' |
| @@ -1436,16 +1549,12 @@ virtualenv." | |||
| 1436 | If DEDICATED is t and the variable `buffer-file-name' is non-nil | 1549 | If DEDICATED is t and the variable `buffer-file-name' is non-nil |
| 1437 | returns a string with the form | 1550 | returns a string with the form |
| 1438 | `python-shell-buffer-name'[variable `buffer-file-name'] else | 1551 | `python-shell-buffer-name'[variable `buffer-file-name'] else |
| 1439 | returns the value of `python-shell-buffer-name'. After | 1552 | returns the value of `python-shell-buffer-name'." |
| 1440 | calculating the process name adds the buffer name for the process | ||
| 1441 | in the `same-window-buffer-names' list." | ||
| 1442 | (let ((process-name | 1553 | (let ((process-name |
| 1443 | (if (and dedicated | 1554 | (if (and dedicated |
| 1444 | buffer-file-name) | 1555 | buffer-file-name) |
| 1445 | (format "%s[%s]" python-shell-buffer-name buffer-file-name) | 1556 | (format "%s[%s]" python-shell-buffer-name buffer-file-name) |
| 1446 | (format "%s" python-shell-buffer-name)))) | 1557 | (format "%s" python-shell-buffer-name)))) |
| 1447 | (add-to-list 'same-window-buffer-names (purecopy | ||
| 1448 | (format "*%s*" process-name))) | ||
| 1449 | process-name)) | 1558 | process-name)) |
| 1450 | 1559 | ||
| 1451 | (defun python-shell-internal-get-process-name () | 1560 | (defun python-shell-internal-get-process-name () |
| @@ -1553,8 +1662,11 @@ variable. | |||
| 1553 | 'python-shell-completion-complete-at-point nil 'local) | 1662 | 'python-shell-completion-complete-at-point nil 'local) |
| 1554 | (add-to-list (make-local-variable 'comint-dynamic-complete-functions) | 1663 | (add-to-list (make-local-variable 'comint-dynamic-complete-functions) |
| 1555 | 'python-shell-completion-complete-at-point) | 1664 | 'python-shell-completion-complete-at-point) |
| 1556 | (define-key inferior-python-mode-map (kbd "<tab>") | 1665 | (define-key inferior-python-mode-map "\t" |
| 1557 | 'python-shell-completion-complete-or-indent) | 1666 | 'python-shell-completion-complete-or-indent) |
| 1667 | (make-local-variable 'python-pdbtrack-buffers-to-kill) | ||
| 1668 | (make-local-variable 'python-pdbtrack-tracked-buffer) | ||
| 1669 | (make-local-variable 'python-shell-internal-last-output) | ||
| 1558 | (when python-shell-enable-font-lock | 1670 | (when python-shell-enable-font-lock |
| 1559 | (set (make-local-variable 'font-lock-defaults) | 1671 | (set (make-local-variable 'font-lock-defaults) |
| 1560 | '(python-font-lock-keywords nil nil nil nil)) | 1672 | '(python-font-lock-keywords nil nil nil nil)) |
| @@ -1562,70 +1674,83 @@ variable. | |||
| 1562 | python-syntax-propertize-function)) | 1674 | python-syntax-propertize-function)) |
| 1563 | (compilation-shell-minor-mode 1)) | 1675 | (compilation-shell-minor-mode 1)) |
| 1564 | 1676 | ||
| 1565 | (defun python-shell-make-comint (cmd proc-name &optional pop) | 1677 | (defun python-shell-make-comint (cmd proc-name &optional pop internal) |
| 1566 | "Create a python shell comint buffer. | 1678 | "Create a python shell comint buffer. |
| 1567 | CMD is the python command to be executed and PROC-NAME is the | 1679 | CMD is the python command to be executed and PROC-NAME is the |
| 1568 | process name the comint buffer will get. After the comint buffer | 1680 | process name the comint buffer will get. After the comint buffer |
| 1569 | is created the `inferior-python-mode' is activated. If POP is | 1681 | is created the `inferior-python-mode' is activated. When |
| 1570 | non-nil the buffer is shown." | 1682 | optional argument POP is non-nil the buffer is shown. When |
| 1683 | optional argument INTERNAL is non-nil this process is run on a | ||
| 1684 | buffer with a name that starts with a space, following the Emacs | ||
| 1685 | convention for temporary/internal buffers, and also makes sure | ||
| 1686 | the user is not queried for confirmation when the process is | ||
| 1687 | killed." | ||
| 1571 | (save-excursion | 1688 | (save-excursion |
| 1572 | (let* ((proc-buffer-name (format "*%s*" proc-name)) | 1689 | (let* ((proc-buffer-name |
| 1690 | (format (if (not internal) "*%s*" " *%s*") proc-name)) | ||
| 1573 | (process-environment (python-shell-calculate-process-environment)) | 1691 | (process-environment (python-shell-calculate-process-environment)) |
| 1574 | (exec-path (python-shell-calculate-exec-path))) | 1692 | (exec-path (python-shell-calculate-exec-path))) |
| 1575 | (when (not (comint-check-proc proc-buffer-name)) | 1693 | (when (not (comint-check-proc proc-buffer-name)) |
| 1576 | (let* ((cmdlist (split-string-and-unquote cmd)) | 1694 | (let* ((cmdlist (split-string-and-unquote cmd)) |
| 1577 | (buffer (apply 'make-comint proc-name (car cmdlist) nil | 1695 | (buffer (apply #'make-comint-in-buffer proc-name proc-buffer-name |
| 1578 | (cdr cmdlist))) | 1696 | (car cmdlist) nil (cdr cmdlist))) |
| 1579 | (current-buffer (current-buffer))) | 1697 | (current-buffer (current-buffer)) |
| 1698 | (process (get-buffer-process buffer))) | ||
| 1580 | (with-current-buffer buffer | 1699 | (with-current-buffer buffer |
| 1581 | (inferior-python-mode) | 1700 | (inferior-python-mode) |
| 1582 | (python-util-clone-local-variables current-buffer)))) | 1701 | (python-util-clone-local-variables current-buffer)) |
| 1583 | (when pop | 1702 | (accept-process-output process) |
| 1584 | (pop-to-buffer proc-buffer-name)) | 1703 | (and pop (pop-to-buffer buffer t)) |
| 1704 | (and internal (set-process-query-on-exit-flag process nil)))) | ||
| 1585 | proc-buffer-name))) | 1705 | proc-buffer-name))) |
| 1586 | 1706 | ||
| 1587 | (defun run-python (dedicated cmd) | 1707 | ;;;###autoload |
| 1708 | (defun run-python (cmd &optional dedicated show) | ||
| 1588 | "Run an inferior Python process. | 1709 | "Run an inferior Python process. |
| 1589 | Input and output via buffer named after | 1710 | Input and output via buffer named after |
| 1590 | `python-shell-buffer-name'. If there is a process already | 1711 | `python-shell-buffer-name'. If there is a process already |
| 1591 | running in that buffer, just switch to it. | 1712 | running in that buffer, just switch to it. |
| 1592 | With argument, allows you to define DEDICATED, so a dedicated | 1713 | |
| 1593 | process for the current buffer is open, and define CMD so you can | 1714 | With argument, allows you to define CMD so you can edit the |
| 1594 | edit the command used to call the interpreter (default is value | 1715 | command used to call the interpreter and define DEDICATED, so a |
| 1595 | of `python-shell-interpreter' and arguments defined in | 1716 | dedicated process for the current buffer is open. When numeric |
| 1596 | `python-shell-interpreter-args'). Runs the hook | 1717 | prefix arg is other than 0 or 4 do not SHOW. |
| 1597 | `inferior-python-mode-hook' (after the `comint-mode-hook' is | 1718 | |
| 1598 | run). | 1719 | Runs the hook `inferior-python-mode-hook' (after the |
| 1599 | \(Type \\[describe-mode] in the process buffer for a list of commands.)" | 1720 | `comint-mode-hook' is run). \(Type \\[describe-mode] in the |
| 1721 | process buffer for a list of commands.)" | ||
| 1600 | (interactive | 1722 | (interactive |
| 1601 | (if current-prefix-arg | 1723 | (if current-prefix-arg |
| 1602 | (list | 1724 | (list |
| 1725 | (read-string "Run Python: " (python-shell-parse-command)) | ||
| 1603 | (y-or-n-p "Make dedicated process? ") | 1726 | (y-or-n-p "Make dedicated process? ") |
| 1604 | (read-string "Run Python: " (python-shell-parse-command))) | 1727 | (= (prefix-numeric-value current-prefix-arg) 4)) |
| 1605 | (list nil (python-shell-parse-command)))) | 1728 | (list (python-shell-parse-command) nil t))) |
| 1606 | (python-shell-make-comint cmd (python-shell-get-process-name dedicated)) | 1729 | (python-shell-make-comint |
| 1730 | cmd (python-shell-get-process-name dedicated) show) | ||
| 1607 | dedicated) | 1731 | dedicated) |
| 1608 | 1732 | ||
| 1609 | (defun run-python-internal () | 1733 | (defun run-python-internal () |
| 1610 | "Run an inferior Internal Python process. | 1734 | "Run an inferior Internal Python process. |
| 1611 | Input and output via buffer named after | 1735 | Input and output via buffer named after |
| 1612 | `python-shell-internal-buffer-name' and what | 1736 | `python-shell-internal-buffer-name' and what |
| 1613 | `python-shell-internal-get-process-name' returns. This new kind | 1737 | `python-shell-internal-get-process-name' returns. |
| 1614 | of shell is intended to be used for generic communication related | 1738 | |
| 1615 | to defined configurations. The main difference with global or | 1739 | This new kind of shell is intended to be used for generic |
| 1616 | dedicated shells is that these ones are attached to a | 1740 | communication related to defined configurations, the main |
| 1617 | configuration, not a buffer. This means that can be used for | 1741 | difference with global or dedicated shells is that these ones are |
| 1618 | example to retrieve the sys.path and other stuff, without messing | 1742 | attached to a configuration, not a buffer. This means that can |
| 1619 | with user shells. Runs the hook | 1743 | be used for example to retrieve the sys.path and other stuff, |
| 1620 | `inferior-python-mode-hook' (after the `comint-mode-hook' is | 1744 | without messing with user shells. Note that |
| 1621 | run). \(Type \\[describe-mode] in the process buffer for a list | 1745 | `python-shell-enable-font-lock' and `inferior-python-mode-hook' |
| 1622 | of commands.)" | 1746 | are set to nil for these shells, so setup codes are not sent at |
| 1623 | (interactive) | 1747 | startup." |
| 1624 | (set-process-query-on-exit-flag | 1748 | (let ((python-shell-enable-font-lock nil) |
| 1625 | (get-buffer-process | 1749 | (inferior-python-mode-hook nil)) |
| 1626 | (python-shell-make-comint | 1750 | (get-buffer-process |
| 1627 | (python-shell-parse-command) | 1751 | (python-shell-make-comint |
| 1628 | (python-shell-internal-get-process-name))) nil)) | 1752 | (python-shell-parse-command) |
| 1753 | (python-shell-internal-get-process-name) nil t)))) | ||
| 1629 | 1754 | ||
| 1630 | (defun python-shell-get-process () | 1755 | (defun python-shell-get-process () |
| 1631 | "Get inferior Python process for current buffer and return it." | 1756 | "Get inferior Python process for current buffer and return it." |
| @@ -1647,7 +1772,7 @@ of commands.)" | |||
| 1647 | (global-proc-buffer-name (format "*%s*" global-proc-name)) | 1772 | (global-proc-buffer-name (format "*%s*" global-proc-name)) |
| 1648 | (dedicated-running (comint-check-proc dedicated-proc-buffer-name)) | 1773 | (dedicated-running (comint-check-proc dedicated-proc-buffer-name)) |
| 1649 | (global-running (comint-check-proc global-proc-buffer-name)) | 1774 | (global-running (comint-check-proc global-proc-buffer-name)) |
| 1650 | (current-prefix-arg 4)) | 1775 | (current-prefix-arg 16)) |
| 1651 | (when (and (not dedicated-running) (not global-running)) | 1776 | (when (and (not dedicated-running) (not global-running)) |
| 1652 | (if (call-interactively 'run-python) | 1777 | (if (call-interactively 'run-python) |
| 1653 | (setq dedicated-running t) | 1778 | (setq dedicated-running t) |
| @@ -1661,21 +1786,35 @@ of commands.)" | |||
| 1661 | "Current internal shell buffer for the current buffer. | 1786 | "Current internal shell buffer for the current buffer. |
| 1662 | This is really not necessary at all for the code to work but it's | 1787 | This is really not necessary at all for the code to work but it's |
| 1663 | there for compatibility with CEDET.") | 1788 | there for compatibility with CEDET.") |
| 1664 | (make-variable-buffer-local 'python-shell-internal-buffer) | 1789 | |
| 1790 | (defvar python-shell-internal-last-output nil | ||
| 1791 | "Last output captured by the internal shell. | ||
| 1792 | This is really not necessary at all for the code to work but it's | ||
| 1793 | there for compatibility with CEDET.") | ||
| 1665 | 1794 | ||
| 1666 | (defun python-shell-internal-get-or-create-process () | 1795 | (defun python-shell-internal-get-or-create-process () |
| 1667 | "Get or create an inferior Internal Python process." | 1796 | "Get or create an inferior Internal Python process." |
| 1668 | (let* ((proc-name (python-shell-internal-get-process-name)) | 1797 | (let* ((proc-name (python-shell-internal-get-process-name)) |
| 1669 | (proc-buffer-name (format "*%s*" proc-name))) | 1798 | (proc-buffer-name (format " *%s*" proc-name))) |
| 1670 | (run-python-internal) | 1799 | (when (not (process-live-p proc-name)) |
| 1671 | (setq python-shell-internal-buffer proc-buffer-name) | 1800 | (run-python-internal) |
| 1801 | (setq python-shell-internal-buffer proc-buffer-name) | ||
| 1802 | ;; XXX: Why is this `sit-for' needed? | ||
| 1803 | ;; `python-shell-make-comint' calls `accept-process-output' | ||
| 1804 | ;; already but it is not helping to get proper output on | ||
| 1805 | ;; 'gnu/linux when the internal shell process is not running and | ||
| 1806 | ;; a call to `python-shell-internal-send-string' is issued. | ||
| 1807 | (sit-for 0.1 t)) | ||
| 1672 | (get-buffer-process proc-buffer-name))) | 1808 | (get-buffer-process proc-buffer-name))) |
| 1673 | 1809 | ||
| 1674 | (define-obsolete-function-alias | 1810 | (define-obsolete-function-alias |
| 1675 | 'python-proc 'python-shell-internal-get-or-create-process "24.2") | 1811 | 'python-proc 'python-shell-internal-get-or-create-process "24.3") |
| 1812 | |||
| 1813 | (define-obsolete-variable-alias | ||
| 1814 | 'python-buffer 'python-shell-internal-buffer "24.3") | ||
| 1676 | 1815 | ||
| 1677 | (define-obsolete-variable-alias | 1816 | (define-obsolete-variable-alias |
| 1678 | 'python-buffer 'python-shell-internal-buffer "24.2") | 1817 | 'python-preoutput-result 'python-shell-internal-last-output "24.3") |
| 1679 | 1818 | ||
| 1680 | (defun python-shell-send-string (string &optional process msg) | 1819 | (defun python-shell-send-string (string &optional process msg) |
| 1681 | "Send STRING to inferior Python PROCESS. | 1820 | "Send STRING to inferior Python PROCESS. |
| @@ -1683,8 +1822,7 @@ When MSG is non-nil messages the first line of STRING." | |||
| 1683 | (interactive "sPython command: ") | 1822 | (interactive "sPython command: ") |
| 1684 | (let ((process (or process (python-shell-get-or-create-process))) | 1823 | (let ((process (or process (python-shell-get-or-create-process))) |
| 1685 | (lines (split-string string "\n" t))) | 1824 | (lines (split-string string "\n" t))) |
| 1686 | (when msg | 1825 | (and msg (message "Sent: %s..." (nth 0 lines))) |
| 1687 | (message (format "Sent: %s..." (nth 0 lines)))) | ||
| 1688 | (if (> (length lines) 1) | 1826 | (if (> (length lines) 1) |
| 1689 | (let* ((temp-file-name (make-temp-file "py")) | 1827 | (let* ((temp-file-name (make-temp-file "py")) |
| 1690 | (file-name (or (buffer-file-name) temp-file-name))) | 1828 | (file-name (or (buffer-file-name) temp-file-name))) |
| @@ -1701,39 +1839,47 @@ When MSG is non-nil messages the first line of STRING." | |||
| 1701 | "Send STRING to PROCESS and inhibit output. | 1839 | "Send STRING to PROCESS and inhibit output. |
| 1702 | When MSG is non-nil messages the first line of STRING. Return | 1840 | When MSG is non-nil messages the first line of STRING. Return |
| 1703 | the output." | 1841 | the output." |
| 1704 | (let* ((output-buffer) | 1842 | (let* ((output-buffer "") |
| 1705 | (process (or process (python-shell-get-or-create-process))) | 1843 | (process (or process (python-shell-get-or-create-process))) |
| 1706 | (comint-preoutput-filter-functions | 1844 | (comint-preoutput-filter-functions |
| 1707 | (append comint-preoutput-filter-functions | 1845 | (append comint-preoutput-filter-functions |
| 1708 | '(ansi-color-filter-apply | 1846 | '(ansi-color-filter-apply |
| 1709 | (lambda (string) | 1847 | (lambda (string) |
| 1710 | (setq output-buffer (concat output-buffer string)) | 1848 | (setq output-buffer (concat output-buffer string)) |
| 1711 | ""))))) | 1849 | "")))) |
| 1712 | (python-shell-send-string string process msg) | 1850 | (inhibit-quit t)) |
| 1713 | (accept-process-output process) | 1851 | (or |
| 1714 | (replace-regexp-in-string | 1852 | (with-local-quit |
| 1715 | (if (> (length python-shell-prompt-output-regexp) 0) | 1853 | (python-shell-send-string string process msg) |
| 1716 | (format "\n*%s$\\|^%s\\|\n$" | 1854 | (accept-process-output process) |
| 1717 | python-shell-prompt-regexp | 1855 | (replace-regexp-in-string |
| 1718 | (or python-shell-prompt-output-regexp "")) | 1856 | (if (> (length python-shell-prompt-output-regexp) 0) |
| 1719 | (format "\n*$\\|^%s\\|\n$" | 1857 | (format "\n*%s$\\|^%s\\|\n$" |
| 1720 | python-shell-prompt-regexp)) | 1858 | python-shell-prompt-regexp |
| 1721 | "" output-buffer))) | 1859 | (or python-shell-prompt-output-regexp "")) |
| 1860 | (format "\n*$\\|^%s\\|\n$" | ||
| 1861 | python-shell-prompt-regexp)) | ||
| 1862 | "" output-buffer)) | ||
| 1863 | (with-current-buffer (process-buffer process) | ||
| 1864 | (comint-interrupt-subjob))))) | ||
| 1722 | 1865 | ||
| 1723 | (defun python-shell-internal-send-string (string) | 1866 | (defun python-shell-internal-send-string (string) |
| 1724 | "Send STRING to the Internal Python interpreter. | 1867 | "Send STRING to the Internal Python interpreter. |
| 1725 | Returns the output. See `python-shell-send-string-no-output'." | 1868 | Returns the output. See `python-shell-send-string-no-output'." |
| 1726 | (python-shell-send-string-no-output | 1869 | ;; XXX Remove `python-shell-internal-last-output' once CEDET is |
| 1727 | ;; Makes this function compatible with the old | 1870 | ;; updated to support this new mode. |
| 1728 | ;; python-send-receive. (At least for CEDET). | 1871 | (setq python-shell-internal-last-output |
| 1729 | (replace-regexp-in-string "_emacs_out +" "" string) | 1872 | (python-shell-send-string-no-output |
| 1730 | (python-shell-internal-get-or-create-process) nil)) | 1873 | ;; Makes this function compatible with the old |
| 1874 | ;; python-send-receive. (At least for CEDET). | ||
| 1875 | (replace-regexp-in-string "_emacs_out +" "" string) | ||
| 1876 | (python-shell-internal-get-or-create-process) nil))) | ||
| 1731 | 1877 | ||
| 1732 | (define-obsolete-function-alias | 1878 | (define-obsolete-function-alias |
| 1733 | 'python-send-receive 'python-shell-internal-send-string "24.2") | 1879 | 'python-send-receive 'python-shell-internal-send-string "24.3") |
| 1734 | 1880 | ||
| 1735 | (define-obsolete-function-alias | 1881 | (define-obsolete-function-alias |
| 1736 | 'python-send-string 'python-shell-internal-send-string "24.2") | 1882 | 'python-send-string 'python-shell-internal-send-string "24.3") |
| 1737 | 1883 | ||
| 1738 | (defun python-shell-send-region (start end) | 1884 | (defun python-shell-send-region (start end) |
| 1739 | "Send the region delimited by START and END to inferior Python process." | 1885 | "Send the region delimited by START and END to inferior Python process." |
| @@ -1806,12 +1952,10 @@ FILE-NAME." | |||
| 1806 | "Send all setup code for shell. | 1952 | "Send all setup code for shell. |
| 1807 | This function takes the list of setup code to send from the | 1953 | This function takes the list of setup code to send from the |
| 1808 | `python-shell-setup-codes' list." | 1954 | `python-shell-setup-codes' list." |
| 1809 | (let ((msg "Sent %s") | 1955 | (let ((process (get-buffer-process (current-buffer)))) |
| 1810 | (process (get-buffer-process (current-buffer)))) | ||
| 1811 | (accept-process-output process python-shell-send-setup-max-wait) | ||
| 1812 | (dolist (code python-shell-setup-codes) | 1956 | (dolist (code python-shell-setup-codes) |
| 1813 | (when code | 1957 | (when code |
| 1814 | (message (format msg code)) | 1958 | (message "Sent %s" code) |
| 1815 | (python-shell-send-string | 1959 | (python-shell-send-string |
| 1816 | (symbol-value code) process))))) | 1960 | (symbol-value code) process))))) |
| 1817 | 1961 | ||
| @@ -1872,27 +2016,71 @@ and use the following as the value of this variable: | |||
| 1872 | :type 'string | 2016 | :type 'string |
| 1873 | :group 'python) | 2017 | :group 'python) |
| 1874 | 2018 | ||
| 1875 | (defun python-shell-completion--get-completions (input process completion-code) | 2019 | (defun python-shell-completion-get-completions (process line input) |
| 1876 | "Retrieve available completions for INPUT using PROCESS. | 2020 | "Do completion at point for PROCESS. |
| 1877 | Argument COMPLETION-CODE is the python code used to get | 2021 | LINE is used to detect the context on how to complete given |
| 1878 | completions on the current context." | 2022 | INPUT." |
| 1879 | (with-current-buffer (process-buffer process) | 2023 | (let* ((prompt |
| 1880 | (let ((completions (python-shell-send-string-no-output | 2024 | ;; Get the last prompt for the inferior process |
| 1881 | (format completion-code input) process))) | 2025 | ;; buffer. This is used for the completion code selection |
| 1882 | (when (> (length completions) 2) | 2026 | ;; heuristic. |
| 1883 | (split-string completions "^'\\|^\"\\|;\\|'$\\|\"$" t))))) | 2027 | (with-current-buffer (process-buffer process) |
| 1884 | 2028 | (buffer-substring-no-properties | |
| 1885 | (defun python-shell-completion--do-completion-at-point (process) | 2029 | (overlay-start comint-last-prompt-overlay) |
| 1886 | "Do completion at point for PROCESS." | 2030 | (overlay-end comint-last-prompt-overlay)))) |
| 1887 | (with-syntax-table python-dotty-syntax-table | 2031 | (completion-context |
| 1888 | (let* ((beg | 2032 | ;; Check whether a prompt matches a pdb string, an import |
| 1889 | (save-excursion | 2033 | ;; statement or just the standard prompt and use the |
| 2034 | ;; correct python-shell-completion-*-code string | ||
| 2035 | (cond ((and (> (length python-shell-completion-pdb-string-code) 0) | ||
| 2036 | (string-match | ||
| 2037 | (concat "^" python-shell-prompt-pdb-regexp) prompt)) | ||
| 2038 | 'pdb) | ||
| 2039 | ((and (> | ||
| 2040 | (length python-shell-completion-module-string-code) 0) | ||
| 2041 | (string-match | ||
| 2042 | (concat "^" python-shell-prompt-regexp) prompt) | ||
| 2043 | (string-match "^[ \t]*\\(from\\|import\\)[ \t]" line)) | ||
| 2044 | 'import) | ||
| 2045 | ((string-match | ||
| 2046 | (concat "^" python-shell-prompt-regexp) prompt) | ||
| 2047 | 'default) | ||
| 2048 | (t nil))) | ||
| 2049 | (completion-code | ||
| 2050 | (case completion-context | ||
| 2051 | (pdb python-shell-completion-pdb-string-code) | ||
| 2052 | (import python-shell-completion-module-string-code) | ||
| 2053 | (default python-shell-completion-string-code) | ||
| 2054 | (t nil))) | ||
| 2055 | (input | ||
| 2056 | (if (eq completion-context 'import) | ||
| 2057 | (replace-regexp-in-string "^[ \t]+" "" line) | ||
| 2058 | input))) | ||
| 2059 | (and completion-code | ||
| 2060 | (> (length input) 0) | ||
| 2061 | (with-current-buffer (process-buffer process) | ||
| 2062 | (let ((completions (python-shell-send-string-no-output | ||
| 2063 | (format completion-code input) process))) | ||
| 2064 | (and (> (length completions) 2) | ||
| 2065 | (split-string completions | ||
| 2066 | "^'\\|^\"\\|;\\|'$\\|\"$" t))))))) | ||
| 2067 | |||
| 2068 | (defun python-shell-completion-complete-at-point (&optional process) | ||
| 2069 | "Perform completion at point in inferior Python. | ||
| 2070 | Optional argument PROCESS forces completions to be retrieved | ||
| 2071 | using that one instead of current buffer's process." | ||
| 2072 | (setq process (or process (get-buffer-process (current-buffer)))) | ||
| 2073 | (let* ((start | ||
| 2074 | (save-excursion | ||
| 2075 | (with-syntax-table python-dotty-syntax-table | ||
| 1890 | (let* ((paren-depth (car (syntax-ppss))) | 2076 | (let* ((paren-depth (car (syntax-ppss))) |
| 1891 | (syntax-string "w_") | 2077 | (syntax-string "w_") |
| 1892 | (syntax-list (string-to-syntax syntax-string))) | 2078 | (syntax-list (string-to-syntax syntax-string))) |
| 1893 | ;; Stop scanning for the beginning of the completion subject | 2079 | ;; Stop scanning for the beginning of the completion |
| 1894 | ;; after the char before point matches a delimiter | 2080 | ;; subject after the char before point matches a |
| 1895 | (while (member (car (syntax-after (1- (point)))) syntax-list) | 2081 | ;; delimiter |
| 2082 | (while (member | ||
| 2083 | (car (syntax-after (1- (point)))) syntax-list) | ||
| 1896 | (skip-syntax-backward syntax-string) | 2084 | (skip-syntax-backward syntax-string) |
| 1897 | (when (or (equal (char-before) ?\)) | 2085 | (when (or (equal (char-before) ?\)) |
| 1898 | (equal (char-before) ?\")) | 2086 | (equal (char-before) ?\")) |
| @@ -1900,60 +2088,16 @@ completions on the current context." | |||
| 1900 | (while (or | 2088 | (while (or |
| 1901 | ;; honor initial paren depth | 2089 | ;; honor initial paren depth |
| 1902 | (> (car (syntax-ppss)) paren-depth) | 2090 | (> (car (syntax-ppss)) paren-depth) |
| 1903 | (python-info-ppss-context 'string)) | 2091 | (python-syntax-context 'string)) |
| 1904 | (forward-char -1)))) | 2092 | (forward-char -1))) |
| 1905 | (point))) | 2093 | (point))))) |
| 1906 | (end (point)) | 2094 | (end (point))) |
| 1907 | (line (buffer-substring-no-properties (point-at-bol) end)) | 2095 | (list start end |
| 1908 | (input (buffer-substring-no-properties beg end)) | 2096 | (completion-table-dynamic |
| 1909 | ;; Get the last prompt for the inferior process buffer. This is | 2097 | (apply-partially |
| 1910 | ;; used for the completion code selection heuristic. | 2098 | #'python-shell-completion-get-completions |
| 1911 | (prompt | 2099 | process (buffer-substring-no-properties |
| 1912 | (with-current-buffer (process-buffer process) | 2100 | (line-beginning-position) end)))))) |
| 1913 | (buffer-substring-no-properties | ||
| 1914 | (overlay-start comint-last-prompt-overlay) | ||
| 1915 | (overlay-end comint-last-prompt-overlay)))) | ||
| 1916 | (completion-context | ||
| 1917 | ;; Check whether a prompt matches a pdb string, an import statement | ||
| 1918 | ;; or just the standard prompt and use the correct | ||
| 1919 | ;; python-shell-completion-*-code string | ||
| 1920 | (cond ((and (> (length python-shell-completion-pdb-string-code) 0) | ||
| 1921 | (string-match | ||
| 1922 | (concat "^" python-shell-prompt-pdb-regexp) prompt)) | ||
| 1923 | 'pdb) | ||
| 1924 | ((and (> | ||
| 1925 | (length python-shell-completion-module-string-code) 0) | ||
| 1926 | (string-match | ||
| 1927 | (concat "^" python-shell-prompt-regexp) prompt) | ||
| 1928 | (string-match "^[ \t]*\\(from\\|import\\)[ \t]" line)) | ||
| 1929 | 'import) | ||
| 1930 | ((string-match | ||
| 1931 | (concat "^" python-shell-prompt-regexp) prompt) | ||
| 1932 | 'default) | ||
| 1933 | (t nil))) | ||
| 1934 | (completion-code | ||
| 1935 | (case completion-context | ||
| 1936 | ('pdb python-shell-completion-pdb-string-code) | ||
| 1937 | ('import python-shell-completion-module-string-code) | ||
| 1938 | ('default python-shell-completion-string-code) | ||
| 1939 | (t nil))) | ||
| 1940 | (input | ||
| 1941 | (if (eq completion-context 'import) | ||
| 1942 | (replace-regexp-in-string "^[ \t]+" "" line) | ||
| 1943 | input)) | ||
| 1944 | (completions | ||
| 1945 | (and completion-code (> (length input) 0) | ||
| 1946 | (python-shell-completion--get-completions | ||
| 1947 | input process completion-code)))) | ||
| 1948 | (list beg end completions)))) | ||
| 1949 | |||
| 1950 | (defun python-shell-completion-complete-at-point () | ||
| 1951 | "Perform completion at point in inferior Python process." | ||
| 1952 | (interactive) | ||
| 1953 | (and comint-last-prompt-overlay | ||
| 1954 | (> (point-marker) (overlay-end comint-last-prompt-overlay)) | ||
| 1955 | (python-shell-completion--do-completion-at-point | ||
| 1956 | (get-buffer-process (current-buffer))))) | ||
| 1957 | 2101 | ||
| 1958 | (defun python-shell-completion-complete-or-indent () | 2102 | (defun python-shell-completion-complete-or-indent () |
| 1959 | "Complete or indent depending on the context. | 2103 | "Complete or indent depending on the context. |
| @@ -1987,11 +2131,9 @@ Used to extract the current line and module being inspected." | |||
| 1987 | "Variable containing the value of the current tracked buffer. | 2131 | "Variable containing the value of the current tracked buffer. |
| 1988 | Never set this variable directly, use | 2132 | Never set this variable directly, use |
| 1989 | `python-pdbtrack-set-tracked-buffer' instead.") | 2133 | `python-pdbtrack-set-tracked-buffer' instead.") |
| 1990 | (make-variable-buffer-local 'python-pdbtrack-tracked-buffer) | ||
| 1991 | 2134 | ||
| 1992 | (defvar python-pdbtrack-buffers-to-kill nil | 2135 | (defvar python-pdbtrack-buffers-to-kill nil |
| 1993 | "List of buffers to be deleted after tracking finishes.") | 2136 | "List of buffers to be deleted after tracking finishes.") |
| 1994 | (make-variable-buffer-local 'python-pdbtrack-buffers-to-kill) | ||
| 1995 | 2137 | ||
| 1996 | (defun python-pdbtrack-set-tracked-buffer (file-name) | 2138 | (defun python-pdbtrack-set-tracked-buffer (file-name) |
| 1997 | "Set the buffer for FILE-NAME as the tracked buffer. | 2139 | "Set the buffer for FILE-NAME as the tracked buffer. |
| @@ -2064,11 +2206,10 @@ Argument OUTPUT is a string with the output from the comint process." | |||
| 2064 | For this to work the best as possible you should call | 2206 | For this to work the best as possible you should call |
| 2065 | `python-shell-send-buffer' from time to time so context in | 2207 | `python-shell-send-buffer' from time to time so context in |
| 2066 | inferior python process is updated properly." | 2208 | inferior python process is updated properly." |
| 2067 | (interactive) | ||
| 2068 | (let ((process (python-shell-get-process))) | 2209 | (let ((process (python-shell-get-process))) |
| 2069 | (if (not process) | 2210 | (if (not process) |
| 2070 | (error "Completion needs an inferior Python process running") | 2211 | (error "Completion needs an inferior Python process running") |
| 2071 | (python-shell-completion--do-completion-at-point process)))) | 2212 | (python-shell-completion-complete-at-point process)))) |
| 2072 | 2213 | ||
| 2073 | (add-to-list 'debug-ignored-errors | 2214 | (add-to-list 'debug-ignored-errors |
| 2074 | "^Completion needs an inferior Python process running.") | 2215 | "^Completion needs an inferior Python process running.") |
| @@ -2122,7 +2263,7 @@ Optional argument JUSTIFY defines if the paragraph should be justified." | |||
| 2122 | ((funcall python-fill-comment-function justify)) | 2263 | ((funcall python-fill-comment-function justify)) |
| 2123 | ;; Strings/Docstrings | 2264 | ;; Strings/Docstrings |
| 2124 | ((save-excursion (skip-chars-forward "\"'uUrR") | 2265 | ((save-excursion (skip-chars-forward "\"'uUrR") |
| 2125 | (python-info-ppss-context 'string)) | 2266 | (python-syntax-context 'string)) |
| 2126 | (funcall python-fill-string-function justify)) | 2267 | (funcall python-fill-string-function justify)) |
| 2127 | ;; Decorators | 2268 | ;; Decorators |
| 2128 | ((equal (char-after (save-excursion | 2269 | ((equal (char-after (save-excursion |
| @@ -2130,7 +2271,7 @@ Optional argument JUSTIFY defines if the paragraph should be justified." | |||
| 2130 | (point-marker))) ?@) | 2271 | (point-marker))) ?@) |
| 2131 | (funcall python-fill-decorator-function justify)) | 2272 | (funcall python-fill-decorator-function justify)) |
| 2132 | ;; Parens | 2273 | ;; Parens |
| 2133 | ((or (python-info-ppss-context 'paren) | 2274 | ((or (python-syntax-context 'paren) |
| 2134 | (looking-at (python-rx open-paren)) | 2275 | (looking-at (python-rx open-paren)) |
| 2135 | (save-excursion | 2276 | (save-excursion |
| 2136 | (skip-syntax-forward "^(" (line-end-position)) | 2277 | (skip-syntax-forward "^(" (line-end-position)) |
| @@ -2150,13 +2291,13 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." | |||
| 2150 | (string-start-marker | 2291 | (string-start-marker |
| 2151 | (progn | 2292 | (progn |
| 2152 | (skip-chars-forward "\"'uUrR") | 2293 | (skip-chars-forward "\"'uUrR") |
| 2153 | (goto-char (python-info-ppss-context 'string)) | 2294 | (goto-char (python-syntax-context 'string)) |
| 2154 | (skip-chars-forward "\"'uUrR") | 2295 | (skip-chars-forward "\"'uUrR") |
| 2155 | (point-marker))) | 2296 | (point-marker))) |
| 2156 | (reg-start (line-beginning-position)) | 2297 | (reg-start (line-beginning-position)) |
| 2157 | (string-end-marker | 2298 | (string-end-marker |
| 2158 | (progn | 2299 | (progn |
| 2159 | (while (python-info-ppss-context 'string) | 2300 | (while (python-syntax-context 'string) |
| 2160 | (goto-char (1+ (point-marker)))) | 2301 | (goto-char (1+ (point-marker)))) |
| 2161 | (skip-chars-backward "\"'") | 2302 | (skip-chars-backward "\"'") |
| 2162 | (point-marker))) | 2303 | (point-marker))) |
| @@ -2194,16 +2335,16 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." | |||
| 2194 | JUSTIFY should be used (if applicable) as in `fill-paragraph'." | 2335 | JUSTIFY should be used (if applicable) as in `fill-paragraph'." |
| 2195 | (save-restriction | 2336 | (save-restriction |
| 2196 | (narrow-to-region (progn | 2337 | (narrow-to-region (progn |
| 2197 | (while (python-info-ppss-context 'paren) | 2338 | (while (python-syntax-context 'paren) |
| 2198 | (goto-char (1- (point-marker)))) | 2339 | (goto-char (1- (point-marker)))) |
| 2199 | (point-marker) | 2340 | (point-marker) |
| 2200 | (line-beginning-position)) | 2341 | (line-beginning-position)) |
| 2201 | (progn | 2342 | (progn |
| 2202 | (when (not (python-info-ppss-context 'paren)) | 2343 | (when (not (python-syntax-context 'paren)) |
| 2203 | (end-of-line) | 2344 | (end-of-line) |
| 2204 | (when (not (python-info-ppss-context 'paren)) | 2345 | (when (not (python-syntax-context 'paren)) |
| 2205 | (skip-syntax-backward "^)"))) | 2346 | (skip-syntax-backward "^)"))) |
| 2206 | (while (python-info-ppss-context 'paren) | 2347 | (while (python-syntax-context 'paren) |
| 2207 | (goto-char (1+ (point-marker)))) | 2348 | (goto-char (1+ (point-marker)))) |
| 2208 | (point-marker))) | 2349 | (point-marker))) |
| 2209 | (let ((paragraph-start "\f\\|[ \t]*$") | 2350 | (let ((paragraph-start "\f\\|[ \t]*$") |
| @@ -2228,7 +2369,7 @@ the if condition." | |||
| 2228 | :safe 'booleanp) | 2369 | :safe 'booleanp) |
| 2229 | 2370 | ||
| 2230 | (define-obsolete-variable-alias | 2371 | (define-obsolete-variable-alias |
| 2231 | 'python-use-skeletons 'python-skeleton-autoinsert "24.2") | 2372 | 'python-use-skeletons 'python-skeleton-autoinsert "24.3") |
| 2232 | 2373 | ||
| 2233 | (defvar python-skeleton-available '() | 2374 | (defvar python-skeleton-available '() |
| 2234 | "Internal list of available skeletons.") | 2375 | "Internal list of available skeletons.") |
| @@ -2241,8 +2382,7 @@ the if condition." | |||
| 2241 | ;; Only expand in code. | 2382 | ;; Only expand in code. |
| 2242 | :enable-function (lambda () | 2383 | :enable-function (lambda () |
| 2243 | (and | 2384 | (and |
| 2244 | (not (or (python-info-ppss-context 'string) | 2385 | (not (python-syntax-comment-or-string-p)) |
| 2245 | (python-info-ppss-context 'comment))) | ||
| 2246 | python-skeleton-autoinsert))) | 2386 | python-skeleton-autoinsert))) |
| 2247 | 2387 | ||
| 2248 | (defmacro python-skeleton-define (name doc &rest skel) | 2388 | (defmacro python-skeleton-define (name doc &rest skel) |
| @@ -2254,7 +2394,7 @@ be added to `python-mode-abbrev-table'." | |||
| 2254 | (function-name (intern (concat "python-skeleton-" name)))) | 2394 | (function-name (intern (concat "python-skeleton-" name)))) |
| 2255 | `(progn | 2395 | `(progn |
| 2256 | (define-abbrev python-mode-abbrev-table ,name "" ',function-name | 2396 | (define-abbrev python-mode-abbrev-table ,name "" ',function-name |
| 2257 | :system t) | 2397 | :system t) |
| 2258 | (setq python-skeleton-available | 2398 | (setq python-skeleton-available |
| 2259 | (cons ',function-name python-skeleton-available)) | 2399 | (cons ',function-name python-skeleton-available)) |
| 2260 | (define-skeleton ,function-name | 2400 | (define-skeleton ,function-name |
| @@ -2479,46 +2619,19 @@ Runs COMMAND, a shell command, as if by `compile'. See | |||
| 2479 | 2619 | ||
| 2480 | (defun python-eldoc--get-doc-at-point (&optional force-input force-process) | 2620 | (defun python-eldoc--get-doc-at-point (&optional force-input force-process) |
| 2481 | "Internal implementation to get documentation at point. | 2621 | "Internal implementation to get documentation at point. |
| 2482 | If not FORCE-INPUT is passed then what `current-word' returns | 2622 | If not FORCE-INPUT is passed then what |
| 2483 | will be used. If not FORCE-PROCESS is passed what | 2623 | `python-info-current-symbol' returns will be used. If not |
| 2484 | `python-shell-get-process' returns is used." | 2624 | FORCE-PROCESS is passed what `python-shell-get-process' returns |
| 2625 | is used." | ||
| 2485 | (let ((process (or force-process (python-shell-get-process)))) | 2626 | (let ((process (or force-process (python-shell-get-process)))) |
| 2486 | (if (not process) | 2627 | (if (not process) |
| 2487 | "Eldoc needs an inferior Python process running." | 2628 | (error "Eldoc needs an inferior Python process running") |
| 2488 | (let* ((current-defun (python-info-current-defun)) | 2629 | (let ((input (or force-input |
| 2489 | (input (or force-input | 2630 | (python-info-current-symbol t)))) |
| 2490 | (with-syntax-table python-dotty-syntax-table | 2631 | (and input |
| 2491 | (if (not current-defun) | 2632 | (python-shell-send-string-no-output |
| 2492 | (current-word) | 2633 | (format python-eldoc-string-code input) |
| 2493 | (concat current-defun "." (current-word)))))) | 2634 | process)))))) |
| 2494 | (ppss (syntax-ppss)) | ||
| 2495 | (help (when (and | ||
| 2496 | input | ||
| 2497 | (not (string= input (concat current-defun "."))) | ||
| 2498 | (not (or (python-info-ppss-context 'string ppss) | ||
| 2499 | (python-info-ppss-context 'comment ppss)))) | ||
| 2500 | (when (string-match | ||
| 2501 | (concat | ||
| 2502 | (regexp-quote (concat current-defun ".")) | ||
| 2503 | "self\\.") input) | ||
| 2504 | (with-temp-buffer | ||
| 2505 | (insert input) | ||
| 2506 | (goto-char (point-min)) | ||
| 2507 | (forward-word) | ||
| 2508 | (forward-char) | ||
| 2509 | (delete-region | ||
| 2510 | (point-marker) (search-forward "self.")) | ||
| 2511 | (setq input (buffer-substring | ||
| 2512 | (point-min) (point-max))))) | ||
| 2513 | (python-shell-send-string-no-output | ||
| 2514 | (format python-eldoc-string-code input) process)))) | ||
| 2515 | (with-current-buffer (process-buffer process) | ||
| 2516 | (when comint-last-prompt-overlay | ||
| 2517 | (delete-region comint-last-input-end | ||
| 2518 | (overlay-start comint-last-prompt-overlay)))) | ||
| 2519 | (when (and help | ||
| 2520 | (not (string= help "\n"))) | ||
| 2521 | help))))) | ||
| 2522 | 2635 | ||
| 2523 | (defun python-eldoc-function () | 2636 | (defun python-eldoc-function () |
| 2524 | "`eldoc-documentation-function' for Python. | 2637 | "`eldoc-documentation-function' for Python. |
| @@ -2531,17 +2644,16 @@ inferior python process is updated properly." | |||
| 2531 | "Get help on SYMBOL using `help'. | 2644 | "Get help on SYMBOL using `help'. |
| 2532 | Interactively, prompt for symbol." | 2645 | Interactively, prompt for symbol." |
| 2533 | (interactive | 2646 | (interactive |
| 2534 | (let ((symbol (with-syntax-table python-dotty-syntax-table | 2647 | (let ((symbol (python-info-current-symbol t)) |
| 2535 | (current-word))) | ||
| 2536 | (enable-recursive-minibuffers t)) | 2648 | (enable-recursive-minibuffers t)) |
| 2537 | (list (read-string (if symbol | 2649 | (list (read-string (if symbol |
| 2538 | (format "Describe symbol (default %s): " symbol) | 2650 | (format "Describe symbol (default %s): " symbol) |
| 2539 | "Describe symbol: ") | 2651 | "Describe symbol: ") |
| 2540 | nil nil symbol)))) | 2652 | nil nil symbol)))) |
| 2541 | (let ((process (python-shell-get-process))) | 2653 | (message (python-eldoc--get-doc-at-point symbol))) |
| 2542 | (if (not process) | 2654 | |
| 2543 | (message "Eldoc needs an inferior Python process running.") | 2655 | (add-to-list 'debug-ignored-errors |
| 2544 | (message (python-eldoc--get-doc-at-point symbol process))))) | 2656 | "^Eldoc needs an inferior Python process running.") |
| 2545 | 2657 | ||
| 2546 | 2658 | ||
| 2547 | ;;; Misc helpers | 2659 | ;;; Misc helpers |
| @@ -2553,18 +2665,27 @@ This function is compatible to be used as | |||
| 2553 | `add-log-current-defun-function' since it returns nil if point is | 2665 | `add-log-current-defun-function' since it returns nil if point is |
| 2554 | not inside a defun." | 2666 | not inside a defun." |
| 2555 | (let ((names '()) | 2667 | (let ((names '()) |
| 2556 | (min-indent) | 2668 | (starting-indentation) |
| 2669 | (starting-point) | ||
| 2557 | (first-run t)) | 2670 | (first-run t)) |
| 2558 | (save-restriction | 2671 | (save-restriction |
| 2559 | (widen) | 2672 | (widen) |
| 2560 | (save-excursion | 2673 | (save-excursion |
| 2674 | (setq starting-point (point-marker)) | ||
| 2675 | (setq starting-indentation (save-excursion | ||
| 2676 | (python-nav-beginning-of-statement) | ||
| 2677 | (current-indentation))) | ||
| 2561 | (end-of-line 1) | 2678 | (end-of-line 1) |
| 2562 | (setq min-indent (current-indentation)) | ||
| 2563 | (while (python-beginning-of-defun-function 1) | 2679 | (while (python-beginning-of-defun-function 1) |
| 2564 | (when (or (< (current-indentation) min-indent) | 2680 | (when (or (< (current-indentation) starting-indentation) |
| 2565 | first-run) | 2681 | (and first-run |
| 2682 | (< | ||
| 2683 | starting-point | ||
| 2684 | (save-excursion | ||
| 2685 | (python-end-of-defun-function) | ||
| 2686 | (point-marker))))) | ||
| 2566 | (setq first-run nil) | 2687 | (setq first-run nil) |
| 2567 | (setq min-indent (current-indentation)) | 2688 | (setq starting-indentation (current-indentation)) |
| 2568 | (looking-at python-nav-beginning-of-defun-regexp) | 2689 | (looking-at python-nav-beginning-of-defun-regexp) |
| 2569 | (setq names (cons | 2690 | (setq names (cons |
| 2570 | (if (not include-type) | 2691 | (if (not include-type) |
| @@ -2576,6 +2697,36 @@ not inside a defun." | |||
| 2576 | (when names | 2697 | (when names |
| 2577 | (mapconcat (lambda (string) string) names ".")))) | 2698 | (mapconcat (lambda (string) string) names ".")))) |
| 2578 | 2699 | ||
| 2700 | (defun python-info-current-symbol (&optional replace-self) | ||
| 2701 | "Return current symbol using dotty syntax. | ||
| 2702 | With optional argument REPLACE-SELF convert \"self\" to current | ||
| 2703 | parent defun name." | ||
| 2704 | (let ((name | ||
| 2705 | (and (not (python-syntax-comment-or-string-p)) | ||
| 2706 | (with-syntax-table python-dotty-syntax-table | ||
| 2707 | (let ((sym (symbol-at-point))) | ||
| 2708 | (and sym | ||
| 2709 | (substring-no-properties (symbol-name sym)))))))) | ||
| 2710 | (when name | ||
| 2711 | (if (not replace-self) | ||
| 2712 | name | ||
| 2713 | (let ((current-defun (python-info-current-defun))) | ||
| 2714 | (if (not current-defun) | ||
| 2715 | name | ||
| 2716 | (replace-regexp-in-string | ||
| 2717 | (python-rx line-start word-start "self" word-end ?.) | ||
| 2718 | (concat | ||
| 2719 | (mapconcat 'identity | ||
| 2720 | (butlast (split-string current-defun "\\.")) | ||
| 2721 | ".") ".") | ||
| 2722 | name))))))) | ||
| 2723 | |||
| 2724 | (defsubst python-info-beginning-of-block-statement-p () | ||
| 2725 | "Return non-nil if current statement opens a block." | ||
| 2726 | (save-excursion | ||
| 2727 | (python-nav-beginning-of-statement) | ||
| 2728 | (looking-at (python-rx block-start)))) | ||
| 2729 | |||
| 2579 | (defun python-info-closing-block () | 2730 | (defun python-info-closing-block () |
| 2580 | "Return the point of the block the current line closes." | 2731 | "Return the point of the block the current line closes." |
| 2581 | (let ((closing-word (save-excursion | 2732 | (let ((closing-word (save-excursion |
| @@ -2629,7 +2780,7 @@ With optional argument LINE-NUMBER, check that line instead." | |||
| 2629 | (goto-char line-number)) | 2780 | (goto-char line-number)) |
| 2630 | (while (and (not (eobp)) | 2781 | (while (and (not (eobp)) |
| 2631 | (goto-char (line-end-position)) | 2782 | (goto-char (line-end-position)) |
| 2632 | (python-info-ppss-context 'paren) | 2783 | (python-syntax-context 'paren) |
| 2633 | (not (equal (char-before (point)) ?\\))) | 2784 | (not (equal (char-before (point)) ?\\))) |
| 2634 | (forward-line 1)) | 2785 | (forward-line 1)) |
| 2635 | (when (equal (char-before) ?\\) | 2786 | (when (equal (char-before) ?\\) |
| @@ -2646,7 +2797,7 @@ Optional argument LINE-NUMBER forces the line number to check against." | |||
| 2646 | (when (python-info-line-ends-backslash-p) | 2797 | (when (python-info-line-ends-backslash-p) |
| 2647 | (while (save-excursion | 2798 | (while (save-excursion |
| 2648 | (goto-char (line-beginning-position)) | 2799 | (goto-char (line-beginning-position)) |
| 2649 | (python-info-ppss-context 'paren)) | 2800 | (python-syntax-context 'paren)) |
| 2650 | (forward-line -1)) | 2801 | (forward-line -1)) |
| 2651 | (back-to-indentation) | 2802 | (back-to-indentation) |
| 2652 | (point-marker))))) | 2803 | (point-marker))))) |
| @@ -2660,31 +2811,27 @@ where the continued line ends." | |||
| 2660 | (widen) | 2811 | (widen) |
| 2661 | (let* ((context-type (progn | 2812 | (let* ((context-type (progn |
| 2662 | (back-to-indentation) | 2813 | (back-to-indentation) |
| 2663 | (python-info-ppss-context-type))) | 2814 | (python-syntax-context-type))) |
| 2664 | (line-start (line-number-at-pos)) | 2815 | (line-start (line-number-at-pos)) |
| 2665 | (context-start (when context-type | 2816 | (context-start (when context-type |
| 2666 | (python-info-ppss-context context-type)))) | 2817 | (python-syntax-context context-type)))) |
| 2667 | (cond ((equal context-type 'paren) | 2818 | (cond ((equal context-type 'paren) |
| 2668 | ;; Lines inside a paren are always a continuation line | 2819 | ;; Lines inside a paren are always a continuation line |
| 2669 | ;; (except the first one). | 2820 | ;; (except the first one). |
| 2670 | (when (equal (python-info-ppss-context-type) 'paren) | 2821 | (python-util-forward-comment -1) |
| 2671 | (python-util-forward-comment -1) | 2822 | (point-marker)) |
| 2672 | (python-util-forward-comment -1) | 2823 | ((member context-type '(string comment)) |
| 2673 | (point-marker))) | ||
| 2674 | ((or (equal context-type 'comment) | ||
| 2675 | (equal context-type 'string)) | ||
| 2676 | ;; move forward an roll again | 2824 | ;; move forward an roll again |
| 2677 | (goto-char context-start) | 2825 | (goto-char context-start) |
| 2678 | (python-util-forward-comment) | 2826 | (python-util-forward-comment) |
| 2679 | (python-info-continuation-line-p)) | 2827 | (python-info-continuation-line-p)) |
| 2680 | (t | 2828 | (t |
| 2681 | ;; Not within a paren, string or comment, the only way we are | 2829 | ;; Not within a paren, string or comment, the only way |
| 2682 | ;; dealing with a continuation line is that previous line | 2830 | ;; we are dealing with a continuation line is that |
| 2683 | ;; contains a backslash, and this can only be the previous line | 2831 | ;; previous line contains a backslash, and this can |
| 2684 | ;; from current | 2832 | ;; only be the previous line from current |
| 2685 | (back-to-indentation) | 2833 | (back-to-indentation) |
| 2686 | (python-util-forward-comment -1) | 2834 | (python-util-forward-comment -1) |
| 2687 | (python-util-forward-comment -1) | ||
| 2688 | (when (and (equal (1- line-start) (line-number-at-pos)) | 2835 | (when (and (equal (1- line-start) (line-number-at-pos)) |
| 2689 | (python-info-line-ends-backslash-p)) | 2836 | (python-info-line-ends-backslash-p)) |
| 2690 | (point-marker)))))))) | 2837 | (point-marker)))))))) |
| @@ -2712,44 +2859,13 @@ operator." | |||
| 2712 | assignment-operator | 2859 | assignment-operator |
| 2713 | not-simple-operator) | 2860 | not-simple-operator) |
| 2714 | (line-end-position) t) | 2861 | (line-end-position) t) |
| 2715 | (not (or (python-info-ppss-context 'string) | 2862 | (not (python-syntax-context-type)))) |
| 2716 | (python-info-ppss-context 'paren) | ||
| 2717 | (python-info-ppss-context 'comment))))) | ||
| 2718 | (skip-syntax-forward "\s") | 2863 | (skip-syntax-forward "\s") |
| 2719 | (point-marker))))) | 2864 | (point-marker))))) |
| 2720 | 2865 | ||
| 2721 | (defun python-info-ppss-context (type &optional syntax-ppss) | ||
| 2722 | "Return non-nil if point is on TYPE using SYNTAX-PPSS. | ||
| 2723 | TYPE can be 'comment, 'string or 'paren. It returns the start | ||
| 2724 | character address of the specified TYPE." | ||
| 2725 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 2726 | (case type | ||
| 2727 | ('comment | ||
| 2728 | (and (nth 4 ppss) | ||
| 2729 | (nth 8 ppss))) | ||
| 2730 | ('string | ||
| 2731 | (nth 8 ppss)) | ||
| 2732 | ('paren | ||
| 2733 | (nth 1 ppss)) | ||
| 2734 | (t nil)))) | ||
| 2735 | |||
| 2736 | (defun python-info-ppss-context-type (&optional syntax-ppss) | ||
| 2737 | "Return the context type using SYNTAX-PPSS. | ||
| 2738 | The type returned can be 'comment, 'string or 'paren." | ||
| 2739 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 2740 | (cond | ||
| 2741 | ((and (nth 4 ppss) | ||
| 2742 | (nth 8 ppss)) | ||
| 2743 | 'comment) | ||
| 2744 | ((nth 8 ppss) | ||
| 2745 | 'string) | ||
| 2746 | ((nth 1 ppss) | ||
| 2747 | 'paren) | ||
| 2748 | (t nil)))) | ||
| 2749 | |||
| 2750 | (defun python-info-looking-at-beginning-of-defun (&optional syntax-ppss) | 2866 | (defun python-info-looking-at-beginning-of-defun (&optional syntax-ppss) |
| 2751 | "Check if point is at `beginning-of-defun' using SYNTAX-PPSS." | 2867 | "Check if point is at `beginning-of-defun' using SYNTAX-PPSS." |
| 2752 | (and (not (python-info-ppss-context-type (or syntax-ppss (syntax-ppss)))) | 2868 | (and (not (python-syntax-context-type (or syntax-ppss (syntax-ppss)))) |
| 2753 | (save-excursion | 2869 | (save-excursion |
| 2754 | (beginning-of-line 1) | 2870 | (beginning-of-line 1) |
| 2755 | (looking-at python-nav-beginning-of-defun-regexp)))) | 2871 | (looking-at python-nav-beginning-of-defun-regexp)))) |
| @@ -2795,7 +2911,7 @@ to \"^python-\"." | |||
| 2795 | (defun python-util-forward-comment (&optional direction) | 2911 | (defun python-util-forward-comment (&optional direction) |
| 2796 | "Python mode specific version of `forward-comment'. | 2912 | "Python mode specific version of `forward-comment'. |
| 2797 | Optional argument DIRECTION defines the direction to move to." | 2913 | Optional argument DIRECTION defines the direction to move to." |
| 2798 | (let ((comment-start (python-info-ppss-context 'comment)) | 2914 | (let ((comment-start (python-syntax-context 'comment)) |
| 2799 | (factor (if (< (or direction 0) 0) | 2915 | (factor (if (< (or direction 0) 0) |
| 2800 | -99999 | 2916 | -99999 |
| 2801 | 99999))) | 2917 | 99999))) |
| @@ -2821,7 +2937,7 @@ if that value is non-nil." | |||
| 2821 | (set (make-local-variable 'parse-sexp-ignore-comments) t) | 2937 | (set (make-local-variable 'parse-sexp-ignore-comments) t) |
| 2822 | 2938 | ||
| 2823 | (set (make-local-variable 'forward-sexp-function) | 2939 | (set (make-local-variable 'forward-sexp-function) |
| 2824 | 'python-nav-forward-sexp-function) | 2940 | 'python-nav-forward-sexp) |
| 2825 | 2941 | ||
| 2826 | (set (make-local-variable 'font-lock-defaults) | 2942 | (set (make-local-variable 'font-lock-defaults) |
| 2827 | '(python-font-lock-keywords nil nil nil nil)) | 2943 | '(python-font-lock-keywords nil nil nil nil)) |
| @@ -2882,9 +2998,17 @@ if that value is non-nil." | |||
| 2882 | 2998 | ||
| 2883 | (python-skeleton-add-menu-items) | 2999 | (python-skeleton-add-menu-items) |
| 2884 | 3000 | ||
| 3001 | (make-local-variable 'python-shell-internal-buffer) | ||
| 3002 | |||
| 2885 | (when python-indent-guess-indent-offset | 3003 | (when python-indent-guess-indent-offset |
| 2886 | (python-indent-guess-indent-offset))) | 3004 | (python-indent-guess-indent-offset))) |
| 2887 | 3005 | ||
| 2888 | 3006 | ||
| 2889 | (provide 'python) | 3007 | (provide 'python) |
| 3008 | |||
| 3009 | ;; Local Variables: | ||
| 3010 | ;; coding: utf-8 | ||
| 3011 | ;; indent-tabs-mode: nil | ||
| 3012 | ;; End: | ||
| 3013 | |||
| 2890 | ;;; python.el ends here | 3014 | ;;; python.el ends here |
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 5d79437c3c2..457c7fee36c 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -150,8 +150,7 @@ This should only be called after matching against `ruby-here-doc-beg-re'." | |||
| 150 | (define-key map (kbd "M-C-q") 'ruby-indent-exp) | 150 | (define-key map (kbd "M-C-q") 'ruby-indent-exp) |
| 151 | (define-key map (kbd "C-M-h") 'backward-kill-word) | 151 | (define-key map (kbd "C-M-h") 'backward-kill-word) |
| 152 | (define-key map (kbd "C-j") 'reindent-then-newline-and-indent) | 152 | (define-key map (kbd "C-j") 'reindent-then-newline-and-indent) |
| 153 | (define-key map (kbd "C-m") 'newline) | 153 | (define-key map (kbd "C-c {") 'ruby-toggle-block) |
| 154 | (define-key map (kbd "C-c C-c") 'comment-region) | ||
| 155 | map) | 154 | map) |
| 156 | "Keymap used in Ruby mode.") | 155 | "Keymap used in Ruby mode.") |
| 157 | 156 | ||
| @@ -380,11 +379,19 @@ and `\\' when preceded by `?'." | |||
| 380 | ((and (eq c ?:) (or (not b) (eq (char-syntax b) ? )))) | 379 | ((and (eq c ?:) (or (not b) (eq (char-syntax b) ? )))) |
| 381 | ((eq c ?\\) (eq b ??))))) | 380 | ((eq c ?\\) (eq b ??))))) |
| 382 | 381 | ||
| 382 | (defun ruby-singleton-class-p (&optional pos) | ||
| 383 | (save-excursion | ||
| 384 | (when pos (goto-char pos)) | ||
| 385 | (forward-word -1) | ||
| 386 | (and (or (bolp) (not (eq (char-before (point)) ?_))) | ||
| 387 | (looking-at "class\\s *<<")))) | ||
| 388 | |||
| 383 | (defun ruby-expr-beg (&optional option) | 389 | (defun ruby-expr-beg (&optional option) |
| 384 | "TODO: document." | 390 | "TODO: document." |
| 385 | (save-excursion | 391 | (save-excursion |
| 386 | (store-match-data nil) | 392 | (store-match-data nil) |
| 387 | (let ((space (skip-chars-backward " \t"))) | 393 | (let ((space (skip-chars-backward " \t")) |
| 394 | (start (point))) | ||
| 388 | (cond | 395 | (cond |
| 389 | ((bolp) t) | 396 | ((bolp) t) |
| 390 | ((progn | 397 | ((progn |
| @@ -393,7 +400,8 @@ and `\\' when preceded by `?'." | |||
| 393 | (or (eq (char-syntax (char-before (point))) ?w) | 400 | (or (eq (char-syntax (char-before (point))) ?w) |
| 394 | (ruby-special-char-p)))) | 401 | (ruby-special-char-p)))) |
| 395 | nil) | 402 | nil) |
| 396 | ((and (eq option 'heredoc) (< space 0)) t) | 403 | ((and (eq option 'heredoc) (< space 0)) |
| 404 | (not (progn (goto-char start) (ruby-singleton-class-p)))) | ||
| 397 | ((or (looking-at ruby-operator-re) | 405 | ((or (looking-at ruby-operator-re) |
| 398 | (looking-at "[\\[({,;]") | 406 | (looking-at "[\\[({,;]") |
| 399 | (and (looking-at "[!?]") | 407 | (and (looking-at "[!?]") |
| @@ -409,7 +417,7 @@ and `\\' when preceded by `?'." | |||
| 409 | ruby-block-mid-keywords) | 417 | ruby-block-mid-keywords) |
| 410 | 'words)) | 418 | 'words)) |
| 411 | (goto-char (match-end 0)) | 419 | (goto-char (match-end 0)) |
| 412 | (not (looking-at "\\s_"))) | 420 | (not (looking-at "\\s_\\|!"))) |
| 413 | ((eq option 'expr-qstr) | 421 | ((eq option 'expr-qstr) |
| 414 | (looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]")) | 422 | (looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]")) |
| 415 | ((eq option 'expr-re) | 423 | ((eq option 'expr-re) |
| @@ -581,9 +589,7 @@ and `\\' when preceded by `?'." | |||
| 581 | (eq ?. w))))) | 589 | (eq ?. w))))) |
| 582 | (goto-char pnt) | 590 | (goto-char pnt) |
| 583 | (setq w (char-after (point))) | 591 | (setq w (char-after (point))) |
| 584 | (not (eq ?_ w)) | ||
| 585 | (not (eq ?! w)) | 592 | (not (eq ?! w)) |
| 586 | (not (eq ?? w)) | ||
| 587 | (skip-chars-forward " \t") | 593 | (skip-chars-forward " \t") |
| 588 | (goto-char (match-beginning 0)) | 594 | (goto-char (match-beginning 0)) |
| 589 | (or (not (looking-at ruby-modifier-re)) | 595 | (or (not (looking-at ruby-modifier-re)) |
| @@ -594,7 +600,7 @@ and `\\' when preceded by `?'." | |||
| 594 | (goto-char pnt)) | 600 | (goto-char pnt)) |
| 595 | ((looking-at ":\\(['\"]\\)") | 601 | ((looking-at ":\\(['\"]\\)") |
| 596 | (goto-char (match-beginning 1)) | 602 | (goto-char (match-beginning 1)) |
| 597 | (ruby-forward-string (buffer-substring (match-beginning 1) (match-end 1)) end)) | 603 | (ruby-forward-string (match-string 1) end t)) |
| 598 | ((looking-at ":\\([-,.+*/%&|^~<>]=?\\|===?\\|<=>\\|![~=]?\\)") | 604 | ((looking-at ":\\([-,.+*/%&|^~<>]=?\\|===?\\|<=>\\|![~=]?\\)") |
| 599 | (goto-char (match-end 0))) | 605 | (goto-char (match-end 0))) |
| 600 | ((looking-at ":\\([a-zA-Z_][a-zA-Z_0-9]*[!?=]?\\)?") | 606 | ((looking-at ":\\([a-zA-Z_][a-zA-Z_0-9]*[!?=]?\\)?") |
| @@ -794,7 +800,7 @@ and `\\' when preceded by `?'." | |||
| 794 | ;; (not (or (eolp) (looking-at "#") | 800 | ;; (not (or (eolp) (looking-at "#") |
| 795 | ;; (and (eq (car (nth 1 state)) ?{) | 801 | ;; (and (eq (car (nth 1 state)) ?{) |
| 796 | ;; (looking-at "|")))))) | 802 | ;; (looking-at "|")))))) |
| 797 | ;; Not a regexp or general delimited literal. | 803 | ;; Not a regexp or percent literal. |
| 798 | (null (nth 0 (ruby-parse-region (or begin parse-start) | 804 | (null (nth 0 (ruby-parse-region (or begin parse-start) |
| 799 | (point)))) | 805 | (point)))) |
| 800 | (or (not (eq ?| (char-after (point)))) | 806 | (or (not (eq ?| (char-after (point)))) |
| @@ -875,10 +881,11 @@ or blocks containing the current block." | |||
| 875 | ;; TODO: Make this work for n > 1, | 881 | ;; TODO: Make this work for n > 1, |
| 876 | ;; make it not loop for n = 0, | 882 | ;; make it not loop for n = 0, |
| 877 | ;; document body | 883 | ;; document body |
| 878 | (let (start pos done down) | 884 | (let ((orig (point)) |
| 879 | (setq start (ruby-calculate-indent)) | 885 | (start (ruby-calculate-indent)) |
| 880 | (setq down (looking-at (if (< n 0) ruby-block-end-re | 886 | (down (looking-at (if (< n 0) ruby-block-end-re |
| 881 | (concat "\\<\\(" ruby-block-beg-re "\\)\\>")))) | 887 | (concat "\\<\\(" ruby-block-beg-re "\\)\\>")))) |
| 888 | pos done) | ||
| 882 | (while (and (not done) (not (if (< n 0) (bobp) (eobp)))) | 889 | (while (and (not done) (not (if (< n 0) (bobp) (eobp)))) |
| 883 | (forward-line n) | 890 | (forward-line n) |
| 884 | (cond | 891 | (cond |
| @@ -901,8 +908,18 @@ or blocks containing the current block." | |||
| 901 | (save-excursion | 908 | (save-excursion |
| 902 | (back-to-indentation) | 909 | (back-to-indentation) |
| 903 | (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>")) | 910 | (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>")) |
| 904 | (setq done nil)))))) | 911 | (setq done nil))))) |
| 905 | (back-to-indentation)) | 912 | (back-to-indentation) |
| 913 | (when (< n 0) | ||
| 914 | (let ((eol (point-at-eol)) state next) | ||
| 915 | (if (< orig eol) (setq eol orig)) | ||
| 916 | (setq orig (point)) | ||
| 917 | (while (and (setq next (apply 'ruby-parse-partial eol state)) | ||
| 918 | (< (point) eol)) | ||
| 919 | (setq state next)) | ||
| 920 | (when (cdaadr state) | ||
| 921 | (goto-char (cdaadr state))) | ||
| 922 | (backward-word))))) | ||
| 906 | 923 | ||
| 907 | (defun ruby-beginning-of-block (&optional arg) | 924 | (defun ruby-beginning-of-block (&optional arg) |
| 908 | "Move backward to the beginning of the current block. | 925 | "Move backward to the beginning of the current block. |
| @@ -1110,18 +1127,70 @@ See `add-log-current-defun-function'." | |||
| 1110 | (if mlist (concat mlist mname) mname) | 1127 | (if mlist (concat mlist mname) mname) |
| 1111 | mlist))))) | 1128 | mlist))))) |
| 1112 | 1129 | ||
| 1130 | (defun ruby-brace-to-do-end () | ||
| 1131 | (when (looking-at "{") | ||
| 1132 | (let ((orig (point)) (end (progn (ruby-forward-sexp) (point)))) | ||
| 1133 | (when (eq (char-before) ?\}) | ||
| 1134 | (delete-char -1) | ||
| 1135 | (if (eq (char-syntax (char-before)) ?w) | ||
| 1136 | (insert " ")) | ||
| 1137 | (insert "end") | ||
| 1138 | (if (eq (char-syntax (char-after)) ?w) | ||
| 1139 | (insert " ")) | ||
| 1140 | (goto-char orig) | ||
| 1141 | (delete-char 1) | ||
| 1142 | (if (eq (char-syntax (char-before)) ?w) | ||
| 1143 | (insert " ")) | ||
| 1144 | (insert "do") | ||
| 1145 | (when (looking-at "\\sw\\||") | ||
| 1146 | (insert " ") | ||
| 1147 | (backward-char)) | ||
| 1148 | t)))) | ||
| 1149 | |||
| 1150 | (defun ruby-do-end-to-brace () | ||
| 1151 | (when (and (or (bolp) | ||
| 1152 | (not (memq (char-syntax (char-before)) '(?w ?_)))) | ||
| 1153 | (looking-at "\\<do\\(\\s \\|$\\)")) | ||
| 1154 | (let ((orig (point)) (end (progn (ruby-forward-sexp) (point)))) | ||
| 1155 | (backward-char 3) | ||
| 1156 | (when (looking-at ruby-block-end-re) | ||
| 1157 | (delete-char 3) | ||
| 1158 | (insert "}") | ||
| 1159 | (goto-char orig) | ||
| 1160 | (delete-char 2) | ||
| 1161 | (insert "{") | ||
| 1162 | (if (looking-at "\\s +|") | ||
| 1163 | (delete-char (- (match-end 0) (match-beginning 0) 1))) | ||
| 1164 | t)))) | ||
| 1165 | |||
| 1166 | (defun ruby-toggle-block () | ||
| 1167 | (interactive) | ||
| 1168 | (or (ruby-brace-to-do-end) | ||
| 1169 | (ruby-do-end-to-brace))) | ||
| 1170 | |||
| 1113 | (declare-function ruby-syntax-propertize-heredoc "ruby-mode" (limit)) | 1171 | (declare-function ruby-syntax-propertize-heredoc "ruby-mode" (limit)) |
| 1114 | (declare-function ruby-syntax-general-delimiters-goto-beg "ruby-mode" ()) | 1172 | (declare-function ruby-syntax-enclosing-percent-literal "ruby-mode" (limit)) |
| 1115 | (declare-function ruby-syntax-propertize-general-delimiters "ruby-mode" (limit)) | 1173 | (declare-function ruby-syntax-propertize-percent-literal "ruby-mode" (limit)) |
| 1116 | 1174 | ||
| 1117 | (if (eval-when-compile (fboundp #'syntax-propertize-rules)) | 1175 | (if (eval-when-compile (fboundp #'syntax-propertize-rules)) |
| 1118 | ;; New code that works independently from font-lock. | 1176 | ;; New code that works independently from font-lock. |
| 1119 | (progn | 1177 | (progn |
| 1178 | (eval-and-compile | ||
| 1179 | (defconst ruby-percent-literal-beg-re | ||
| 1180 | "\\(%\\)[qQrswWx]?\\([[:punct:]]\\)" | ||
| 1181 | "Regexp to match the beginning of percent literal.") | ||
| 1182 | |||
| 1183 | (defconst ruby-syntax-methods-before-regexp | ||
| 1184 | '("gsub" "gsub!" "sub" "sub!" "scan" "split" "split!" "index" "match" | ||
| 1185 | "assert_match" "Given" "Then" "When") | ||
| 1186 | "Methods that can take regexp as the first argument. | ||
| 1187 | It will be properly highlighted even when the call omits parens.")) | ||
| 1188 | |||
| 1120 | (defun ruby-syntax-propertize-function (start end) | 1189 | (defun ruby-syntax-propertize-function (start end) |
| 1121 | "Syntactic keywords for Ruby mode. See `syntax-propertize-function'." | 1190 | "Syntactic keywords for Ruby mode. See `syntax-propertize-function'." |
| 1122 | (goto-char start) | 1191 | (goto-char start) |
| 1123 | (ruby-syntax-propertize-heredoc end) | 1192 | (ruby-syntax-propertize-heredoc end) |
| 1124 | (ruby-syntax-general-delimiters-goto-beg) | 1193 | (ruby-syntax-enclosing-percent-literal end) |
| 1125 | (funcall | 1194 | (funcall |
| 1126 | (syntax-propertize-rules | 1195 | (syntax-propertize-rules |
| 1127 | ;; #{ }, #$hoge, #@foo are not comments. | 1196 | ;; #{ }, #$hoge, #@foo are not comments. |
| @@ -1133,36 +1202,34 @@ See `add-log-current-defun-function'." | |||
| 1133 | ;; Not within a string. | 1202 | ;; Not within a string. |
| 1134 | (nth 3 (syntax-ppss (match-beginning 0)))) | 1203 | (nth 3 (syntax-ppss (match-beginning 0)))) |
| 1135 | (string-to-syntax "\\")))) | 1204 | (string-to-syntax "\\")))) |
| 1136 | ;; Regexps: regexps are distinguished from division either because | 1205 | ;; Regexps: regexps are distinguished from division because |
| 1137 | ;; of the keyword/symbol before them, or because of the code | 1206 | ;; of the keyword, symbol, or method name before them. |
| 1138 | ;; following them. | ||
| 1139 | ((concat | 1207 | ((concat |
| 1140 | ;; Special tokens that can't be followed by a division operator. | 1208 | ;; Special tokens that can't be followed by a division operator. |
| 1141 | "\\(?:\\(^\\|[[=(,~?:;<>]\\|\\(?:^\\|\\s \\)" | 1209 | "\\(^\\|[[=(,~?:;<>]" |
| 1210 | ;; Control flow keywords and operators following bol or whitespace. | ||
| 1211 | "\\|\\(?:^\\|\\s \\)" | ||
| 1142 | (regexp-opt '("if" "elsif" "unless" "while" "until" "when" "and" | 1212 | (regexp-opt '("if" "elsif" "unless" "while" "until" "when" "and" |
| 1143 | "or" "&&" "||" | 1213 | "or" "not" "&&" "||")) |
| 1144 | "gsub" "gsub!" "sub" "sub!" "scan" "split" "split!")) | 1214 | ;; Method name from the list. |
| 1145 | "\\)\\s *\\)?" | 1215 | "\\|\\_<" |
| 1216 | (regexp-opt ruby-syntax-methods-before-regexp) | ||
| 1217 | "\\)\\s *" | ||
| 1146 | ;; The regular expression itself. | 1218 | ;; The regular expression itself. |
| 1147 | "\\(/\\)[^/\n\\\\]*\\(?:\\\\.[^/\n\\\\]*\\)*\\(/\\)" | 1219 | "\\(/\\)[^/\n\\\\]*\\(?:\\\\.[^/\n\\\\]*\\)*\\(/\\)") |
| 1148 | ;; Special code that cannot follow a division operator. | 1220 | (2 (string-to-syntax "\"/")) |
| 1149 | ;; FIXME: Just because the second slash of "/foo/ do bar" can't | 1221 | (3 (string-to-syntax "\"/"))) |
| 1150 | ;; be a division, doesn't mean it can't *start* a regexp, as in | ||
| 1151 | ;; "x = toto/foo; if /do bar/". | ||
| 1152 | "\\([imxo]*\\s *\\(?:,\\|\\_<do\\_>\\)\\)?") | ||
| 1153 | (2 (when (or (match-beginning 1) (match-beginning 4)) | ||
| 1154 | (string-to-syntax "\"/"))) | ||
| 1155 | (3 (if (or (match-beginning 1) (match-beginning 4)) | ||
| 1156 | (string-to-syntax "\"/") | ||
| 1157 | (goto-char (match-end 2))))) | ||
| 1158 | ("^=en\\(d\\)\\_>" (1 "!")) | 1222 | ("^=en\\(d\\)\\_>" (1 "!")) |
| 1159 | ("^\\(=\\)begin\\_>" (1 "!")) | 1223 | ("^\\(=\\)begin\\_>" (1 "!")) |
| 1160 | ;; Handle here documents. | 1224 | ;; Handle here documents. |
| 1161 | ((concat ruby-here-doc-beg-re ".*\\(\n\\)") | 1225 | ((concat ruby-here-doc-beg-re ".*\\(\n\\)") |
| 1162 | (7 (prog1 "\"" (ruby-syntax-propertize-heredoc end)))) | 1226 | (7 (unless (ruby-singleton-class-p (match-beginning 0)) |
| 1227 | (put-text-property (match-beginning 7) (match-end 7) | ||
| 1228 | 'syntax-table (string-to-syntax "\"")) | ||
| 1229 | (ruby-syntax-propertize-heredoc end)))) | ||
| 1163 | ;; Handle percent literals: %w(), %q{}, etc. | 1230 | ;; Handle percent literals: %w(), %q{}, etc. |
| 1164 | ("\\(?:^\\|[[ \t\n<+(,=]\\)\\(%\\)[qQrswWx]?\\([[:punct:]]\\)" | 1231 | ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) |
| 1165 | (1 (prog1 "|" (ruby-syntax-propertize-general-delimiters end))))) | 1232 | (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end))))) |
| 1166 | (point) end)) | 1233 | (point) end)) |
| 1167 | 1234 | ||
| 1168 | (defun ruby-syntax-propertize-heredoc (limit) | 1235 | (defun ruby-syntax-propertize-heredoc (limit) |
| @@ -1174,7 +1241,8 @@ See `add-log-current-defun-function'." | |||
| 1174 | (beginning-of-line) | 1241 | (beginning-of-line) |
| 1175 | (while (re-search-forward ruby-here-doc-beg-re | 1242 | (while (re-search-forward ruby-here-doc-beg-re |
| 1176 | (line-end-position) t) | 1243 | (line-end-position) t) |
| 1177 | (push (concat (ruby-here-doc-end-match) "\n") res))) | 1244 | (unless (ruby-singleton-class-p (match-beginning 0)) |
| 1245 | (push (concat (ruby-here-doc-end-match) "\n") res)))) | ||
| 1178 | (let ((start (point))) | 1246 | (let ((start (point))) |
| 1179 | ;; With multiple openers on the same line, we don't know in which | 1247 | ;; With multiple openers on the same line, we don't know in which |
| 1180 | ;; part `start' is, so we have to go back to the beginning. | 1248 | ;; part `start' is, so we have to go back to the beginning. |
| @@ -1189,40 +1257,46 @@ See `add-log-current-defun-function'." | |||
| 1189 | ;; inf-loop. | 1257 | ;; inf-loop. |
| 1190 | (if (< (point) start) (goto-char start)))))) | 1258 | (if (< (point) start) (goto-char start)))))) |
| 1191 | 1259 | ||
| 1192 | (defun ruby-syntax-general-delimiters-goto-beg () | 1260 | (defun ruby-syntax-enclosing-percent-literal (limit) |
| 1193 | (let ((state (syntax-ppss))) | 1261 | (let ((state (syntax-ppss)) |
| 1194 | ;; Move to the start of the literal, in case it's multiline. | 1262 | (start (point))) |
| 1195 | ;; TODO: determine the literal type more reliably here? | 1263 | ;; When already inside percent literal, re-propertize it. |
| 1196 | (when (eq t (nth 3 state)) | 1264 | (when (eq t (nth 3 state)) |
| 1197 | (goto-char (nth 8 state)) | 1265 | (goto-char (nth 8 state)) |
| 1198 | (beginning-of-line)))) | 1266 | (when (looking-at ruby-percent-literal-beg-re) |
| 1267 | (ruby-syntax-propertize-percent-literal limit)) | ||
| 1268 | (when (< (point) start) (goto-char start))))) | ||
| 1199 | 1269 | ||
| 1200 | (defun ruby-syntax-propertize-general-delimiters (limit) | 1270 | (defun ruby-syntax-propertize-percent-literal (limit) |
| 1201 | (goto-char (match-beginning 2)) | 1271 | (goto-char (match-beginning 2)) |
| 1202 | (let* ((op (char-after)) | 1272 | ;; Not inside a simple string or comment. |
| 1203 | (ops (char-to-string op)) | 1273 | (when (eq t (nth 3 (syntax-ppss))) |
| 1204 | (cl (or (cdr (aref (syntax-table) op)) | 1274 | (let* ((op (char-after)) |
| 1205 | (cdr (assoc op '((?< . ?>)))))) | 1275 | (ops (char-to-string op)) |
| 1206 | parse-sexp-lookup-properties) | 1276 | (cl (or (cdr (aref (syntax-table) op)) |
| 1207 | (ignore-errors | 1277 | (cdr (assoc op '((?< . ?>)))))) |
| 1208 | (if cl | 1278 | parse-sexp-lookup-properties) |
| 1209 | (progn ; Paired delimiters. | 1279 | (condition-case nil |
| 1210 | ;; Delimiter pairs of the same kind can be nested | 1280 | (progn |
| 1211 | ;; inside the literal, as long as they are balanced. | 1281 | (if cl ; Paired delimiters. |
| 1212 | ;; Create syntax table that ignores other characters. | 1282 | ;; Delimiter pairs of the same kind can be nested |
| 1213 | (with-syntax-table (make-char-table 'syntax-table nil) | 1283 | ;; inside the literal, as long as they are balanced. |
| 1214 | (modify-syntax-entry op (concat "(" (char-to-string cl))) | 1284 | ;; Create syntax table that ignores other characters. |
| 1215 | (modify-syntax-entry cl (concat ")" ops)) | 1285 | (with-syntax-table (make-char-table 'syntax-table nil) |
| 1216 | (modify-syntax-entry ?\\ "\\") | 1286 | (modify-syntax-entry op (concat "(" (char-to-string cl))) |
| 1217 | (save-restriction | 1287 | (modify-syntax-entry cl (concat ")" ops)) |
| 1218 | (narrow-to-region (point) limit) | 1288 | (modify-syntax-entry ?\\ "\\") |
| 1219 | (forward-list)))) ; skip to the paired character | 1289 | (save-restriction |
| 1220 | ;; Single character delimiter. | 1290 | (narrow-to-region (point) limit) |
| 1221 | (re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*" | 1291 | (forward-list))) ; skip to the paired character |
| 1222 | (regexp-quote ops)) limit nil)) | 1292 | ;; Single character delimiter. |
| 1223 | ;; If we reached here, the closing delimiter was found. | 1293 | (re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*" |
| 1224 | (put-text-property (1- (point)) (point) | 1294 | (regexp-quote ops)) limit nil)) |
| 1225 | 'syntax-table (string-to-syntax "|"))))) | 1295 | ;; Found the closing delimiter. |
| 1296 | (put-text-property (1- (point)) (point) 'syntax-table | ||
| 1297 | (string-to-syntax "|"))) | ||
| 1298 | ;; Unclosed literal, leave the following text unpropertized. | ||
| 1299 | ((scan-error search-failed) (goto-char limit)))))) | ||
| 1226 | ) | 1300 | ) |
| 1227 | 1301 | ||
| 1228 | ;; For Emacsen where syntax-propertize-rules is not (yet) available, | 1302 | ;; For Emacsen where syntax-propertize-rules is not (yet) available, |
| @@ -1267,7 +1341,7 @@ This should only be called after matching against `ruby-here-doc-end-re'." | |||
| 1267 | (4 (7 . ?/)) | 1341 | (4 (7 . ?/)) |
| 1268 | (6 (7 . ?/))) | 1342 | (6 (7 . ?/))) |
| 1269 | ("^=en\\(d\\)\\_>" 1 "!") | 1343 | ("^=en\\(d\\)\\_>" 1 "!") |
| 1270 | ;; General delimited string. | 1344 | ;; Percent literal. |
| 1271 | ("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)" | 1345 | ("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)" |
| 1272 | (3 "\"") | 1346 | (3 "\"") |
| 1273 | (5 "\"")) | 1347 | (5 "\"")) |
| @@ -1310,7 +1384,8 @@ isn't in a string or another comment." | |||
| 1310 | (let ((old-point (point)) (case-fold-search nil)) | 1384 | (let ((old-point (point)) (case-fold-search nil)) |
| 1311 | (beginning-of-line) | 1385 | (beginning-of-line) |
| 1312 | (catch 'found-beg | 1386 | (catch 'found-beg |
| 1313 | (while (re-search-backward ruby-here-doc-beg-re nil t) | 1387 | (while (and (re-search-backward ruby-here-doc-beg-re nil t) |
| 1388 | (not (ruby-singleton-class-p))) | ||
| 1314 | (if (not (or (ruby-in-ppss-context-p 'anything) | 1389 | (if (not (or (ruby-in-ppss-context-p 'anything) |
| 1315 | (ruby-here-doc-find-end old-point))) | 1390 | (ruby-here-doc-find-end old-point))) |
| 1316 | (throw 'found-beg t))))))) | 1391 | (throw 'found-beg t))))))) |
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index f42f661d86c..a6089aabb04 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -327,8 +327,15 @@ shell it really is." | |||
| 327 | (defcustom sh-imenu-generic-expression | 327 | (defcustom sh-imenu-generic-expression |
| 328 | `((sh | 328 | `((sh |
| 329 | . ((nil | 329 | . ((nil |
| 330 | "^\\s-*\\(function\\s-+\\)?\\([[:alpha:]_][[:alnum:]_]+\\)\\s-*()" | 330 | ;; function FOO |
| 331 | 2)))) | 331 | ;; function FOO() |
| 332 | "^\\s-*function\\s-+\\\([[:alpha:]_][[:alnum:]_]+\\)\\s-*\\(?:()\\)?" | ||
| 333 | 1) | ||
| 334 | ;; FOO() | ||
| 335 | (nil | ||
| 336 | "^\\s-*\\([[:alpha:]_][[:alnum:]_]+\\)\\s-*()" | ||
| 337 | 1) | ||
| 338 | ))) | ||
| 332 | "Alist of regular expressions for recognizing shell function definitions. | 339 | "Alist of regular expressions for recognizing shell function definitions. |
| 333 | See `sh-feature' and `imenu-generic-expression'." | 340 | See `sh-feature' and `imenu-generic-expression'." |
| 334 | :type '(alist :key-type (symbol :tag "Shell") | 341 | :type '(alist :key-type (symbol :tag "Shell") |
| @@ -1087,7 +1094,7 @@ subshells can nest." | |||
| 1087 | ;; metacharacters. The list of special chars is taken from | 1094 | ;; metacharacters. The list of special chars is taken from |
| 1088 | ;; the single-unix spec of the shell command language (under | 1095 | ;; the single-unix spec of the shell command language (under |
| 1089 | ;; `quoting') but with `$' removed. | 1096 | ;; `quoting') but with `$' removed. |
| 1090 | ("[^|&;<>()`\\\"' \t\n]\\(#+\\)" (1 "_")) | 1097 | ("\\(?:[^|&;<>()`\\\"' \t\n]\\|\\${\\)\\(#+\\)" (1 "_")) |
| 1091 | ;; In a '...' the backslash is not escaping. | 1098 | ;; In a '...' the backslash is not escaping. |
| 1092 | ("\\(\\\\\\)'" (1 (sh-font-lock-backslash-quote))) | 1099 | ("\\(\\\\\\)'" (1 (sh-font-lock-backslash-quote))) |
| 1093 | ;; Make sure $@ and $? are correctly recognized as sexps. | 1100 | ;; Make sure $@ and $? are correctly recognized as sexps. |
| @@ -1096,12 +1103,12 @@ subshells can nest." | |||
| 1096 | (")" (0 (sh-font-lock-paren (match-beginning 0)))) | 1103 | (")" (0 (sh-font-lock-paren (match-beginning 0)))) |
| 1097 | ;; Highlight (possibly nested) subshells inside "" quoted | 1104 | ;; Highlight (possibly nested) subshells inside "" quoted |
| 1098 | ;; regions correctly. | 1105 | ;; regions correctly. |
| 1099 | ("\"\\(?:\\(?:[^\\\"]\\|\\)*?[^\\]\\(?:\\\\\\\\\\)*\\)??\\(\\$(\\|`\\)" | 1106 | ("\"\\(?:\\(?:[^\\\"]\\|\\\\.\\)*?\\)??\\(\\$(\\|`\\)" |
| 1100 | (1 (ignore | 1107 | (1 (ignore |
| 1101 | ;; Save excursion because we want to also apply other | 1108 | (if (nth 8 (save-excursion (syntax-ppss (match-beginning 0)))) |
| 1102 | ;; syntax-propertize rules within the affected region. | ||
| 1103 | (if (nth 8 (syntax-ppss)) | ||
| 1104 | (goto-char (1+ (match-beginning 0))) | 1109 | (goto-char (1+ (match-beginning 0))) |
| 1110 | ;; Save excursion because we want to also apply other | ||
| 1111 | ;; syntax-propertize rules within the affected region. | ||
| 1105 | (save-excursion | 1112 | (save-excursion |
| 1106 | (sh-font-lock-quoted-subshell end))))))) | 1113 | (sh-font-lock-quoted-subshell end))))))) |
| 1107 | (point) end)) | 1114 | (point) end)) |
| @@ -4069,7 +4076,7 @@ The document is bounded by `sh-here-document-word'." | |||
| 4069 | (self-insert-command (prefix-numeric-value arg)) | 4076 | (self-insert-command (prefix-numeric-value arg)) |
| 4070 | (or arg (sh--maybe-here-document))) | 4077 | (or arg (sh--maybe-here-document))) |
| 4071 | (make-obsolete 'sh--maybe-here-document | 4078 | (make-obsolete 'sh--maybe-here-document |
| 4072 | 'sh-electric-here-document-mode "24.2") | 4079 | 'sh-electric-here-document-mode "24.3") |
| 4073 | 4080 | ||
| 4074 | (defun sh--maybe-here-document () | 4081 | (defun sh--maybe-here-document () |
| 4075 | (or (not (looking-back "[^<]<<")) | 4082 | (or (not (looking-back "[^<]<<")) |
diff --git a/lisp/progmodes/subword.el b/lisp/progmodes/subword.el index 7d8dd4301a2..e541aed8867 100644 --- a/lisp/progmodes/subword.el +++ b/lisp/progmodes/subword.el | |||
| @@ -80,6 +80,20 @@ | |||
| 80 | 80 | ||
| 81 | ;;; Code: | 81 | ;;; Code: |
| 82 | 82 | ||
| 83 | (defvar subword-forward-function 'subword-forward-internal | ||
| 84 | "Function to call for forward subword movement.") | ||
| 85 | |||
| 86 | (defvar subword-backward-function 'subword-backward-internal | ||
| 87 | "Function to call for backward subword movement.") | ||
| 88 | |||
| 89 | (defvar subword-forward-regexp | ||
| 90 | "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)" | ||
| 91 | "Regexp used by `subword-forward-internal'.") | ||
| 92 | |||
| 93 | (defvar subword-backward-regexp | ||
| 94 | "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)\\|\\W\\w+\\)" | ||
| 95 | "Regexp used by `subword-backward-internal'.") | ||
| 96 | |||
| 83 | (defvar subword-mode-map | 97 | (defvar subword-mode-map |
| 84 | (let ((map (make-sparse-keymap))) | 98 | (let ((map (make-sparse-keymap))) |
| 85 | (dolist (cmd '(forward-word backward-word mark-word kill-word | 99 | (dolist (cmd '(forward-word backward-word mark-word kill-word |
| @@ -138,10 +152,10 @@ Optional argument ARG is the same as for `forward-word'." | |||
| 138 | (cond | 152 | (cond |
| 139 | ((< 0 arg) | 153 | ((< 0 arg) |
| 140 | (dotimes (i arg (point)) | 154 | (dotimes (i arg (point)) |
| 141 | (subword-forward-internal))) | 155 | (funcall subword-forward-function))) |
| 142 | ((> 0 arg) | 156 | ((> 0 arg) |
| 143 | (dotimes (i (- arg) (point)) | 157 | (dotimes (i (- arg) (point)) |
| 144 | (subword-backward-internal))) | 158 | (funcall subword-backward-function))) |
| 145 | (t | 159 | (t |
| 146 | (point)))) | 160 | (point)))) |
| 147 | 161 | ||
| @@ -249,9 +263,7 @@ Optional argument ARG is the same as for `capitalize-word'." | |||
| 249 | (if (and | 263 | (if (and |
| 250 | (save-excursion | 264 | (save-excursion |
| 251 | (let ((case-fold-search nil)) | 265 | (let ((case-fold-search nil)) |
| 252 | (re-search-forward | 266 | (re-search-forward subword-forward-regexp nil t))) |
| 253 | (concat "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)") | ||
| 254 | nil t))) | ||
| 255 | (> (match-end 0) (point))) | 267 | (> (match-end 0) (point))) |
| 256 | (goto-char | 268 | (goto-char |
| 257 | (cond | 269 | (cond |
| @@ -265,11 +277,7 @@ Optional argument ARG is the same as for `capitalize-word'." | |||
| 265 | (defun subword-backward-internal () | 277 | (defun subword-backward-internal () |
| 266 | (if (save-excursion | 278 | (if (save-excursion |
| 267 | (let ((case-fold-search nil)) | 279 | (let ((case-fold-search nil)) |
| 268 | (re-search-backward | 280 | (re-search-backward subword-backward-regexp nil t))) |
| 269 | (concat | ||
| 270 | "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)" | ||
| 271 | "\\|\\W\\w+\\)") | ||
| 272 | nil t))) | ||
| 273 | (goto-char | 281 | (goto-char |
| 274 | (cond | 282 | (cond |
| 275 | ((and (match-end 3) | 283 | ((and (match-end 3) |
diff --git a/lisp/progmodes/vhdl-mode.el b/lisp/progmodes/vhdl-mode.el index 5177bc6d9f5..607ccd8b7e7 100644 --- a/lisp/progmodes/vhdl-mode.el +++ b/lisp/progmodes/vhdl-mode.el | |||
| @@ -102,7 +102,7 @@ | |||
| 102 | ;; VHDL Mode distribution. | 102 | ;; VHDL Mode distribution. |
| 103 | 103 | ||
| 104 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 104 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 105 | ;; Acknowledgements | 105 | ;; Acknowledgments |
| 106 | 106 | ||
| 107 | ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu> | 107 | ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu> |
| 108 | ;; and Steve Grout. | 108 | ;; and Steve Grout. |
| @@ -4499,7 +4499,7 @@ Usage: | |||
| 4499 | (mra) architecture is selected. If another architecture is desired, it | 4499 | (mra) architecture is selected. If another architecture is desired, it |
| 4500 | can be marked as most-recently-analyzed (speedbar menu) before | 4500 | can be marked as most-recently-analyzed (speedbar menu) before |
| 4501 | generating the configuration. | 4501 | generating the configuration. |
| 4502 | 4502 | ||
| 4503 | Note: Configurations of subcomponents (i.e. hierarchical configuration | 4503 | Note: Configurations of subcomponents (i.e. hierarchical configuration |
| 4504 | declarations) are currently not considered when displaying | 4504 | declarations) are currently not considered when displaying |
| 4505 | configurations in speedbar. | 4505 | configurations in speedbar. |
| @@ -6979,7 +6979,7 @@ is not moved." | |||
| 6979 | (save-excursion | 6979 | (save-excursion |
| 6980 | (goto-char new) | 6980 | (goto-char new) |
| 6981 | (eq new (progn (back-to-indentation) (point))))) | 6981 | (eq new (progn (back-to-indentation) (point))))) |
| 6982 | (setq placeholder new))) | 6982 | (setq placeholder new))) |
| 6983 | (vhdl-add-syntax 'statement-cont placeholder) | 6983 | (vhdl-add-syntax 'statement-cont placeholder) |
| 6984 | (if begin-after-ip | 6984 | (if begin-after-ip |
| 6985 | (vhdl-add-syntax 'block-open))) | 6985 | (vhdl-add-syntax 'block-open))) |
diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el index 02948b35fe0..02340425dfa 100644 --- a/lisp/progmodes/which-func.el +++ b/lisp/progmodes/which-func.el | |||
| @@ -80,7 +80,7 @@ | |||
| 80 | For other modes it is disabled. If this is equal to t, | 80 | For other modes it is disabled. If this is equal to t, |
| 81 | then Which Function mode is enabled in any major mode that supports it." | 81 | then Which Function mode is enabled in any major mode that supports it." |
| 82 | :group 'which-func | 82 | :group 'which-func |
| 83 | :version "24.2" ; explicit list -> t | 83 | :version "24.3" ; explicit list -> t |
| 84 | :type '(choice (const :tag "All modes" t) | 84 | :type '(choice (const :tag "All modes" t) |
| 85 | (repeat (symbol :tag "Major mode")))) | 85 | (repeat (symbol :tag "Major mode")))) |
| 86 | 86 | ||
| @@ -150,7 +150,7 @@ mouse-2: toggle rest visibility\n\ | |||
| 150 | mouse-3: go to end") | 150 | mouse-3: go to end") |
| 151 | "]") | 151 | "]") |
| 152 | "Format for displaying the function in the mode line." | 152 | "Format for displaying the function in the mode line." |
| 153 | :version "24.2" ; added mouse-face | 153 | :version "24.2" ; added mouse-face; 24point2 is correct |
| 154 | :group 'which-func | 154 | :group 'which-func |
| 155 | :type 'sexp) | 155 | :type 'sexp) |
| 156 | ;;;###autoload (put 'which-func-format 'risky-local-variable t) | 156 | ;;;###autoload (put 'which-func-format 'risky-local-variable t) |