diff options
| author | Martin Rudalics | 2008-09-25 08:39:30 +0000 |
|---|---|---|
| committer | Martin Rudalics | 2008-09-25 08:39:30 +0000 |
| commit | fa9a8f7899a4c0905ae2684922a911ccdaef20b0 (patch) | |
| tree | 3c83f74536204bb586776bd15053ca92ecb4de40 | |
| parent | 4dd7f3750f4f82be7e4f42bbe1e1ebe193da9d2c (diff) | |
| download | emacs-fa9a8f7899a4c0905ae2684922a911ccdaef20b0.tar.gz emacs-fa9a8f7899a4c0905ae2684922a911ccdaef20b0.zip | |
(latex-handle-escaped-parens): New variable.
(latex-backward-sexp-1, latex-forward-sexp-1): Treat escaped
parens specially only if latex-handle-escaped-parens is non-nil.
(latex-indent-within-escaped-parens): New option.
(latex-find-indent): Bind latex-handle-escaped-parens to
latex-indent-within-escaped-parens. Do not treat escaped parens
specially when this is non-nil. (Bug#954)
| -rw-r--r-- | lisp/ChangeLog | 11 | ||||
| -rw-r--r-- | lisp/textmodes/tex-mode.el | 210 |
2 files changed, 127 insertions, 94 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fae9ac0b5c9..18305a1f48a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2008-09-25 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * textmodes/tex-mode.el (latex-handle-escaped-parens): New | ||
| 4 | variable. | ||
| 5 | (latex-backward-sexp-1, latex-forward-sexp-1): Treat escaped | ||
| 6 | parens specially only if latex-handle-escaped-parens is non-nil. | ||
| 7 | (latex-indent-within-escaped-parens): New option. | ||
| 8 | (latex-find-indent): Bind latex-handle-escaped-parens to | ||
| 9 | latex-indent-within-escaped-parens. Do not treat escaped parens | ||
| 10 | specially when this is nil. (Bug#954) | ||
| 11 | |||
| 1 | 2008-09-25 Glenn Morris <rgm@gnu.org> | 12 | 2008-09-25 Glenn Morris <rgm@gnu.org> |
| 2 | 13 | ||
| 3 | * ffap.el (ffap-fixup-url): Don't call url-normalize-url. (Bug#898) | 14 | * ffap.el (ffap-fixup-url): Don't call url-normalize-url. (Bug#898) |
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index 37b2f3657a0..6b516ca6e90 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el | |||
| @@ -1482,18 +1482,25 @@ Mark is left at original location." | |||
| 1482 | (push-mark) | 1482 | (push-mark) |
| 1483 | (goto-char spot))) | 1483 | (goto-char spot))) |
| 1484 | 1484 | ||
| 1485 | (defvar latex-handle-escaped-parens t) | ||
| 1486 | |||
| 1485 | ;; Don't think this one actually _needs_ (for the purposes of | 1487 | ;; Don't think this one actually _needs_ (for the purposes of |
| 1486 | ;; tex-mode) to handle escaped parens. | 1488 | ;; tex-mode) to handle escaped parens. |
| 1489 | ;; Does not handle escaped parens when latex-handle-escaped-parens is nil. | ||
| 1487 | (defun latex-backward-sexp-1 () | 1490 | (defun latex-backward-sexp-1 () |
| 1488 | "Like (backward-sexp 1) but aware of multi-char elements and escaped parens." | 1491 | "Like (backward-sexp 1) but aware of multi-char elements and escaped parens." |
| 1489 | (let ((pos (point)) | 1492 | (let ((pos (point)) |
| 1490 | (forward-sexp-function)) | 1493 | (forward-sexp-function)) |
| 1491 | (backward-sexp 1) | 1494 | (backward-sexp 1) |
| 1492 | (cond ((looking-at "\\\\\\(begin\\>\\|[[({]\\)") | 1495 | (cond ((looking-at |
| 1496 | (if latex-handle-escaped-parens | ||
| 1497 | "\\\\\\(begin\\>\\|[[({]\\)" | ||
| 1498 | "\\\\begin\\>")) | ||
| 1493 | (signal 'scan-error | 1499 | (signal 'scan-error |
| 1494 | (list "Containing expression ends prematurely" | 1500 | (list "Containing expression ends prematurely" |
| 1495 | (point) (prog1 (point) (goto-char pos))))) | 1501 | (point) (prog1 (point) (goto-char pos))))) |
| 1496 | ((looking-at "\\\\\\([])}]\\)") | 1502 | ((and latex-handle-escaped-parens |
| 1503 | (looking-at "\\\\\\([])}]\\)")) | ||
| 1497 | (tex-last-unended-eparen (match-string 1))) | 1504 | (tex-last-unended-eparen (match-string 1))) |
| 1498 | ((eq (char-after) ?{) | 1505 | ((eq (char-after) ?{) |
| 1499 | (let ((newpos (point))) | 1506 | (let ((newpos (point))) |
| @@ -1508,6 +1515,7 @@ Mark is left at original location." | |||
| 1508 | ;; begin/end blocks. | 1515 | ;; begin/end blocks. |
| 1509 | ;; Needs to handle escaped parens for tex-validate-*. | 1516 | ;; Needs to handle escaped parens for tex-validate-*. |
| 1510 | ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00038.html | 1517 | ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00038.html |
| 1518 | ;; Does not handle escaped parens when latex-handle-escaped-parens is nil. | ||
| 1511 | (defun latex-forward-sexp-1 () | 1519 | (defun latex-forward-sexp-1 () |
| 1512 | "Like (forward-sexp 1) but aware of multi-char elements and escaped parens." | 1520 | "Like (forward-sexp 1) but aware of multi-char elements and escaped parens." |
| 1513 | (let ((pos (point)) | 1521 | (let ((pos (point)) |
| @@ -1528,12 +1536,14 @@ Mark is left at original location." | |||
| 1528 | (tex-next-unmatched-end)) | 1536 | (tex-next-unmatched-end)) |
| 1529 | ;; A better way to handle this, \( .. \) etc, is probably to | 1537 | ;; A better way to handle this, \( .. \) etc, is probably to |
| 1530 | ;; temporarily change the syntax of the \ in \( to punctuation. | 1538 | ;; temporarily change the syntax of the \ in \( to punctuation. |
| 1531 | ((looking-back "\\\\[])}]") | 1539 | ((and latex-handle-escaped-parens |
| 1540 | (looking-back "\\\\[])}]")) | ||
| 1532 | (signal 'scan-error | 1541 | (signal 'scan-error |
| 1533 | (list "Containing expression ends prematurely" | 1542 | (list "Containing expression ends prematurely" |
| 1534 | (- (point) 2) (prog1 (point) | 1543 | (- (point) 2) (prog1 (point) |
| 1535 | (goto-char pos))))) | 1544 | (goto-char pos))))) |
| 1536 | ((looking-back "\\\\\\([({[]\\)") | 1545 | ((and latex-handle-escaped-parens |
| 1546 | (looking-back "\\\\\\([({[]\\)")) | ||
| 1537 | (tex-next-unmatched-eparen (match-string 1))) | 1547 | (tex-next-unmatched-eparen (match-string 1))) |
| 1538 | (t (goto-char newpos)))))) | 1548 | (t (goto-char newpos)))))) |
| 1539 | 1549 | ||
| @@ -2568,103 +2578,115 @@ Runs the shell command defined by `tex-show-queue-command'." | |||
| 2568 | (indent-line-to indent) | 2578 | (indent-line-to indent) |
| 2569 | (save-excursion (indent-line-to indent))))))) | 2579 | (save-excursion (indent-line-to indent))))))) |
| 2570 | 2580 | ||
| 2581 | (defcustom latex-indent-within-escaped-parens nil | ||
| 2582 | "Non-nil means add extra indent to text within escaped parens. | ||
| 2583 | When this is non-nil, text within matching pairs of escaped | ||
| 2584 | parens is indented at the column following the open paren. The | ||
| 2585 | default value does not add any extra indent thus providing the | ||
| 2586 | behavior of Emacs 22 and earlier." | ||
| 2587 | :type 'boolean | ||
| 2588 | :group 'tex | ||
| 2589 | :version "23.1") | ||
| 2590 | |||
| 2571 | (defun latex-find-indent (&optional virtual) | 2591 | (defun latex-find-indent (&optional virtual) |
| 2572 | "Find the proper indentation of text after point. | 2592 | "Find the proper indentation of text after point. |
| 2573 | VIRTUAL if non-nil indicates that we're only trying to find the indentation | 2593 | VIRTUAL if non-nil indicates that we're only trying to find the indentation |
| 2574 | in order to determine the indentation of something else. | 2594 | in order to determine the indentation of something else. |
| 2575 | There might be text before point." | 2595 | There might be text before point." |
| 2576 | (save-excursion | 2596 | (let ((latex-handle-escaped-parens latex-indent-within-escaped-parens)) |
| 2577 | (skip-chars-forward " \t") | 2597 | (save-excursion |
| 2578 | (or | 2598 | (skip-chars-forward " \t") |
| 2579 | ;; Stick the first line at column 0. | 2599 | (or |
| 2580 | (and (= (point-min) (line-beginning-position)) 0) | 2600 | ;; Stick the first line at column 0. |
| 2581 | ;; Trust the current indentation, if such info is applicable. | 2601 | (and (= (point-min) (line-beginning-position)) 0) |
| 2582 | (and virtual (save-excursion (skip-chars-backward " \t&") (bolp)) | 2602 | ;; Trust the current indentation, if such info is applicable. |
| 2583 | (current-column)) | 2603 | (and virtual (save-excursion (skip-chars-backward " \t&") (bolp)) |
| 2584 | ;; Stick verbatim environments to the left margin. | 2604 | (current-column)) |
| 2585 | (and (looking-at "\\\\\\(begin\\|end\\) *{\\([^\n}]+\\)") | 2605 | ;; Stick verbatim environments to the left margin. |
| 2586 | (member (match-string 2) tex-verbatim-environments) | 2606 | (and (looking-at "\\\\\\(begin\\|end\\) *{\\([^\n}]+\\)") |
| 2587 | 0) | 2607 | (member (match-string 2) tex-verbatim-environments) |
| 2588 | ;; Put leading close-paren where the matching open paren would be. | 2608 | 0) |
| 2589 | (let (escaped) | 2609 | ;; Put leading close-paren where the matching open paren would be. |
| 2590 | (and (or (eq (latex-syntax-after) ?\)) | 2610 | (let (escaped) |
| 2591 | ;; Try to handle escaped close parens but keep original | 2611 | (and (or (eq (latex-syntax-after) ?\)) |
| 2592 | ;; position if it doesn't work out. | 2612 | ;; Try to handle escaped close parens but keep |
| 2593 | (setq escaped (looking-at "\\\\\\([])}]\\)"))) | 2613 | ;; original position if it doesn't work out. |
| 2594 | (ignore-errors | 2614 | (and latex-handle-escaped-parens |
| 2595 | (save-excursion | 2615 | (setq escaped (looking-at "\\\\\\([])}]\\)")))) |
| 2596 | (when escaped | 2616 | (ignore-errors |
| 2597 | (goto-char (match-beginning 1))) | 2617 | (save-excursion |
| 2598 | (latex-skip-close-parens) | 2618 | (when escaped |
| 2619 | (goto-char (match-beginning 1))) | ||
| 2620 | (latex-skip-close-parens) | ||
| 2621 | (latex-backward-sexp-1) | ||
| 2622 | (latex-find-indent 'virtual))))) | ||
| 2623 | ;; Default (maybe an argument) | ||
| 2624 | (let ((pos (point)) | ||
| 2625 | ;; Outdent \item if necessary. | ||
| 2626 | (indent (if (looking-at tex-indent-item-re) (- tex-indent-item) 0)) | ||
| 2627 | up-list-pos) | ||
| 2628 | ;; Find the previous point which determines our current indentation. | ||
| 2629 | (condition-case err | ||
| 2630 | (progn | ||
| 2599 | (latex-backward-sexp-1) | 2631 | (latex-backward-sexp-1) |
| 2600 | (latex-find-indent 'virtual))))) | 2632 | (while (> (current-column) (current-indentation)) |
| 2601 | ;; Default (maybe an argument) | 2633 | (latex-backward-sexp-1))) |
| 2602 | (let ((pos (point)) | 2634 | (scan-error |
| 2603 | ;; Outdent \item if necessary. | 2635 | (setq up-list-pos (nth 2 err)))) |
| 2604 | (indent (if (looking-at tex-indent-item-re) (- tex-indent-item) 0)) | 2636 | (cond |
| 2605 | up-list-pos) | 2637 | ((= (point-min) pos) 0) ; We're really just indenting the first line. |
| 2606 | ;; Find the previous point which determines our current indentation. | 2638 | ((integerp up-list-pos) |
| 2607 | (condition-case err | 2639 | ;; Have to indent relative to the open-paren. |
| 2608 | (progn | ||
| 2609 | (latex-backward-sexp-1) | ||
| 2610 | (while (> (current-column) (current-indentation)) | ||
| 2611 | (latex-backward-sexp-1))) | ||
| 2612 | (scan-error | ||
| 2613 | (setq up-list-pos (nth 2 err)))) | ||
| 2614 | (cond | ||
| 2615 | ((= (point-min) pos) 0) ; We're really just indenting the first line. | ||
| 2616 | ((integerp up-list-pos) | ||
| 2617 | ;; Have to indent relative to the open-paren. | ||
| 2618 | (goto-char up-list-pos) | ||
| 2619 | (if (and (not tex-indent-allhanging) | ||
| 2620 | (save-excursion | ||
| 2621 | ;; Make sure we're an argument to a macro and | ||
| 2622 | ;; that the macro is at the beginning of a line. | ||
| 2623 | (condition-case nil | ||
| 2624 | (progn | ||
| 2625 | (while (eq (char-syntax (char-after)) ?\() | ||
| 2626 | (forward-sexp -1)) | ||
| 2627 | (and (eq (char-syntax (char-after)) ?/) | ||
| 2628 | (progn (skip-chars-backward " \t&") | ||
| 2629 | (bolp)))) | ||
| 2630 | (scan-error nil))) | ||
| 2631 | (> pos (progn (latex-down-list) | ||
| 2632 | (forward-comment (point-max)) | ||
| 2633 | (point)))) | ||
| 2634 | ;; Align with the first element after the open-paren. | ||
| 2635 | (current-column) | ||
| 2636 | ;; We're the first element after a hanging brace. | ||
| 2637 | (goto-char up-list-pos) | 2640 | (goto-char up-list-pos) |
| 2638 | (+ (if (and (looking-at "\\\\begin *{\\([^\n}]+\\)") | 2641 | (if (and (not tex-indent-allhanging) |
| 2639 | (member (match-string 1) | 2642 | (save-excursion |
| 2640 | latex-noindent-environments)) | 2643 | ;; Make sure we're an argument to a macro and |
| 2641 | 0 tex-indent-basic) | 2644 | ;; that the macro is at the beginning of a line. |
| 2642 | indent (latex-find-indent 'virtual)))) | 2645 | (condition-case nil |
| 2643 | ;; We're now at the "beginning" of a line. | 2646 | (progn |
| 2644 | ((not (and (not virtual) (eq (char-after) ?\\))) | 2647 | (while (eq (char-syntax (char-after)) ?\() |
| 2645 | ;; Nothing particular here: just keep the same indentation. | 2648 | (forward-sexp -1)) |
| 2646 | (+ indent (current-column))) | 2649 | (and (eq (char-syntax (char-after)) ?/) |
| 2647 | ;; We're now looking at a macro call. | 2650 | (progn (skip-chars-backward " \t&") |
| 2648 | ((looking-at tex-indent-item-re) | 2651 | (bolp)))) |
| 2649 | ;; Indenting relative to an item, have to re-add the outdenting. | 2652 | (scan-error nil))) |
| 2650 | (+ indent (current-column) tex-indent-item)) | 2653 | (> pos (progn (latex-down-list) |
| 2651 | (t | 2654 | (forward-comment (point-max)) |
| 2652 | (let ((col (current-column))) | 2655 | (point)))) |
| 2653 | (if (or (not (eq (char-syntax (or (char-after pos) ?\s)) ?\()) | 2656 | ;; Align with the first element after the open-paren. |
| 2654 | ;; Can't be an arg if there's an empty line inbetween. | 2657 | (current-column) |
| 2655 | (save-excursion (re-search-forward "^[ \t]*$" pos t))) | 2658 | ;; We're the first element after a hanging brace. |
| 2656 | ;; If the first char was not an open-paren, there's | 2659 | (goto-char up-list-pos) |
| 2657 | ;; a risk that this is really not an argument to the | 2660 | (+ (if (and (looking-at "\\\\begin *{\\([^\n}]+\\)") |
| 2658 | ;; macro at all. | 2661 | (member (match-string 1) |
| 2659 | (+ indent col) | 2662 | latex-noindent-environments)) |
| 2660 | (forward-sexp 1) | 2663 | 0 tex-indent-basic) |
| 2661 | (if (< (line-end-position) | 2664 | indent (latex-find-indent 'virtual)))) |
| 2662 | (save-excursion (forward-comment (point-max)) | 2665 | ;; We're now at the "beginning" of a line. |
| 2663 | (point))) | 2666 | ((not (and (not virtual) (eq (char-after) ?\\))) |
| 2664 | ;; we're indenting the first argument. | 2667 | ;; Nothing particular here: just keep the same indentation. |
| 2665 | (min (current-column) (+ tex-indent-arg col)) | 2668 | (+ indent (current-column))) |
| 2666 | (skip-syntax-forward " ") | 2669 | ;; We're now looking at a macro call. |
| 2667 | (current-column)))))))))) | 2670 | ((looking-at tex-indent-item-re) |
| 2671 | ;; Indenting relative to an item, have to re-add the outdenting. | ||
| 2672 | (+ indent (current-column) tex-indent-item)) | ||
| 2673 | (t | ||
| 2674 | (let ((col (current-column))) | ||
| 2675 | (if (or (not (eq (char-syntax (or (char-after pos) ?\s)) ?\()) | ||
| 2676 | ;; Can't be an arg if there's an empty line inbetween. | ||
| 2677 | (save-excursion (re-search-forward "^[ \t]*$" pos t))) | ||
| 2678 | ;; If the first char was not an open-paren, there's | ||
| 2679 | ;; a risk that this is really not an argument to the | ||
| 2680 | ;; macro at all. | ||
| 2681 | (+ indent col) | ||
| 2682 | (forward-sexp 1) | ||
| 2683 | (if (< (line-end-position) | ||
| 2684 | (save-excursion (forward-comment (point-max)) | ||
| 2685 | (point))) | ||
| 2686 | ;; we're indenting the first argument. | ||
| 2687 | (min (current-column) (+ tex-indent-arg col)) | ||
| 2688 | (skip-syntax-forward " ") | ||
| 2689 | (current-column))))))))))) | ||
| 2668 | ;;; DocTeX support | 2690 | ;;; DocTeX support |
| 2669 | 2691 | ||
| 2670 | (defun doctex-font-lock-^^A () | 2692 | (defun doctex-font-lock-^^A () |