1767 |
(indent-according-to-mode))))) |
(indent-according-to-mode))))) |
1768 |
|
|
1769 |
|
|
1770 |
|
;;; Verbatim constructs |
1771 |
|
|
1772 |
|
(defcustom LaTeX-verbatim-macros-with-delims |
1773 |
|
'("verb" "verb*") |
1774 |
|
"Macros for inline verbatim with arguments in delimiters, like \\foo|...|." |
1775 |
|
:group 'LaTeX |
1776 |
|
:type '(repeat (string))) |
1777 |
|
|
1778 |
|
(defvar LaTeX-verbatim-macros-with-delims-local nil |
1779 |
|
"Buffer-local variable for inline verbatim with args in delimiters. |
1780 |
|
Style files should add constructs to this variable and not to |
1781 |
|
`LaTeX-verbatim-macros-with-delims'.") |
1782 |
|
(make-variable-buffer-local 'LaTeX-verbatim-macros-with-delims-local) |
1783 |
|
|
1784 |
|
(defcustom LaTeX-verbatim-macros-with-braces nil |
1785 |
|
"Macros for inline verbatim with arguments in braces, like \\foo{...}." |
1786 |
|
:group 'LaTeX |
1787 |
|
:type '(repeat (string))) |
1788 |
|
|
1789 |
|
(defvar LaTeX-verbatim-macros-with-braces-local nil |
1790 |
|
"Buffer-local variable for inline verbatim with args in braces. |
1791 |
|
Style files should add constructs to this variable and not to |
1792 |
|
`LaTeX-verbatim-macros-with-delims'.") |
1793 |
|
(make-variable-buffer-local 'LaTeX-verbatim-macros-with-braces-local) |
1794 |
|
|
1795 |
|
(defcustom LaTeX-verbatim-environments |
1796 |
|
'("verbatim" "verbatim*") |
1797 |
|
"Verbatim environments." |
1798 |
|
:group 'LaTeX |
1799 |
|
:type '(repeat (string))) |
1800 |
|
|
1801 |
|
(defvar LaTeX-verbatim-environments-local nil |
1802 |
|
"Buffer-local variable for inline verbatim environments. |
1803 |
|
Style files should add constructs to this variable and not to |
1804 |
|
`LaTeX-verbatim-environments'.") |
1805 |
|
(make-variable-buffer-local 'LaTeX-verbatim-environments) |
1806 |
|
|
1807 |
|
(defun LaTeX-verbatim-macro-boundaries () |
1808 |
|
"Return boundaries of verbatim macro. |
1809 |
|
Boundaries are returned as a cons cell where the car is the macro |
1810 |
|
start and the cdr the macro end. |
1811 |
|
|
1812 |
|
Only macros which enclose their arguments with special |
1813 |
|
non-parenthetical delimiters, like \\verb+foo+, are recognized." |
1814 |
|
(save-excursion |
1815 |
|
(let ((verbatim-regexp (regexp-opt LaTeX-verbatim-macros-with-delims))) |
1816 |
|
(catch 'found |
1817 |
|
(while (progn |
1818 |
|
(skip-chars-backward (concat "^\n" (regexp-quote TeX-esc)) |
1819 |
|
(line-beginning-position)) |
1820 |
|
(when (looking-at verbatim-regexp) (throw 'found nil)) |
1821 |
|
(forward-char -1) |
1822 |
|
(/= (point) (line-beginning-position))))) |
1823 |
|
(unless (= (point) (line-beginning-position)) |
1824 |
|
(let ((beg (1- (point)))) |
1825 |
|
(goto-char (1+ (match-end 0))) |
1826 |
|
(skip-chars-forward (concat "^" (buffer-substring-no-properties |
1827 |
|
(1- (point)) (point)))) |
1828 |
|
(cons beg (1+ (point)))))))) |
1829 |
|
|
1830 |
|
(defun LaTeX-current-verbatim-macro () |
1831 |
|
"Return name of verbatim macro containing point, nil if none is present." |
1832 |
|
(let ((macro-boundaries (LaTeX-verbatim-macro-boundaries))) |
1833 |
|
(when macro-boundaries |
1834 |
|
(save-excursion |
1835 |
|
(goto-char (car macro-boundaries)) |
1836 |
|
(forward-char (length TeX-esc)) |
1837 |
|
(buffer-substring-no-properties |
1838 |
|
(point) (progn (skip-chars-forward "@A-Za-z") (point))))))) |
1839 |
|
|
1840 |
|
(defun LaTeX-verbatim-p (&optional pos) |
1841 |
|
"Return non-nil if position POS is not in a verbatim-like construct." |
1842 |
|
(when pos (goto-char pos)) |
1843 |
|
(save-match-data |
1844 |
|
(or (when (fboundp 'font-latex-faces-present-p) |
1845 |
|
(font-latex-faces-present-p 'font-latex-verbatim-face)) |
1846 |
|
(assoc (LaTeX-current-verbatim-macro) LaTeX-verbatim-macros-with-delims) |
1847 |
|
(assoc (TeX-current-macro) LaTeX-verbatim-macros-with-braces) |
1848 |
|
(assoc (LaTeX-current-environment) LaTeX-verbatim-environments)))) |
1849 |
|
|
1850 |
|
|
1851 |
;;; Formatting |
;;; Formatting |
1852 |
|
|
1853 |
(defcustom LaTeX-syntactic-comments t |
(defcustom LaTeX-syntactic-comments t |
2341 |
|
|
2342 |
;;; Filling |
;;; Filling |
2343 |
|
|
|
;; FIXME: Consolidate this with `font-latex-verbatim-macros' when |
|
|
;; font-latex.el gets fully integrated in AUCTeX. |
|
|
(defcustom LaTeX-verbatim-macros |
|
|
'("verb" "verb*") |
|
|
"Macros for inline verbatim which should not be broken across lines." |
|
|
:group 'LaTeX |
|
|
:type '(repeat (string))) |
|
|
|
|
2344 |
(defcustom LaTeX-fill-break-at-separators nil |
(defcustom LaTeX-fill-break-at-separators nil |
2345 |
"List of separators before or after which respectively a line |
"List of separators before or after which respectively a line |
2346 |
break will be inserted if they do not fit into one line." |
break will be inserted if they do not fit into one line." |
2562 |
;; This is the actual FILLING LOOP. |
;; This is the actual FILLING LOOP. |
2563 |
(goto-char from) |
(goto-char from) |
2564 |
(let* (linebeg |
(let* (linebeg |
2565 |
(code-comment-flag |
(code-comment-start (save-excursion |
2566 |
(save-excursion |
(LaTeX-back-to-indentation) |
2567 |
(LaTeX-back-to-indentation) |
(LaTeX-search-forward-comment-start |
2568 |
(TeX-re-search-forward-unescaped TeX-comment-start-regexp |
(line-end-position)))) |
2569 |
(line-end-position) t))) |
(end-marker (save-excursion |
2570 |
(end-marker |
(goto-char (or code-comment-start to)) |
2571 |
(save-excursion |
(point-marker))) |
|
(goto-char (if code-comment-flag |
|
|
;; Get the position right after the |
|
|
;; last non-comment-word. |
|
|
(save-excursion |
|
|
(goto-char (match-beginning 0)) |
|
|
(skip-chars-backward " \t") |
|
|
(point)) |
|
|
to)) |
|
|
(point-marker))) |
|
2572 |
(LaTeX-current-environment (LaTeX-current-environment))) |
(LaTeX-current-environment (LaTeX-current-environment))) |
2573 |
;; Fill until point is greater than the end point. If there |
;; Fill until point is greater than the end point. If there |
2574 |
;; is a code comment, use the code comment's start as a |
;; is a code comment, use the code comment's start as a |
2575 |
;; limit. |
;; limit. |
2576 |
(while (and (< (point) (marker-position end-marker)) |
(while (and (< (point) (marker-position end-marker)) |
2577 |
(or (not code-comment-flag) |
(or (not code-comment-start) |
2578 |
(and code-comment-flag |
(and code-comment-start |
2579 |
(> (- (marker-position end-marker) |
(> (- (marker-position end-marker) |
2580 |
(line-beginning-position)) |
(line-beginning-position)) |
2581 |
fill-column)))) |
fill-column)))) |
2606 |
|
|
2607 |
;; Fill a code comment if necessary. (Enable this code if |
;; Fill a code comment if necessary. (Enable this code if |
2608 |
;; you want the comment part in lines with code comments to |
;; you want the comment part in lines with code comments to |
2609 |
;; be filled. It is disabled because the current |
;; be filled. Originally it was disabled because the |
2610 |
;; indentation code will indent the lines following the line |
;; indentation code indented the lines following the line |
2611 |
;; with the code comment to the column of the comment |
;; with the code comment to the column of the comment |
2612 |
;; starters. That means, it will look like this: |
;; starters. That means, it would have looked like this: |
2613 |
;; | code code code % comment |
;; | code code code % comment |
2614 |
;; | % comment |
;; | % comment |
2615 |
;; | code code code |
;; | code code code |
2616 |
;; Not nice, isn't it? But in case indentation code changes, |
;; This now (2005-07-29) is not the case anymore. But as |
2617 |
;; it might be useful, so I leave it here.) |
;; filling code comments like this would split a single |
2618 |
;; (when (and code-comment-flag |
;; paragraph into two separate ones, we still leave it |
2619 |
|
;; disabled. I leave the code here in case it is useful for |
2620 |
|
;; somebody. |
2621 |
|
;; (when (and code-comment-start |
2622 |
;; (> (- (line-end-position) (line-beginning-position)) |
;; (> (- (line-end-position) (line-beginning-position)) |
2623 |
;; fill-column)) |
;; fill-column)) |
2624 |
;; (LaTeX-fill-code-comment justify)) |
;; (LaTeX-fill-code-comment justify)) |
2628 |
;; will be broken before the last non-comment word if the |
;; will be broken before the last non-comment word if the |
2629 |
;; code comment does not fit into the line. |
;; code comment does not fit into the line. |
2630 |
(when (and LaTeX-fill-break-before-code-comments |
(when (and LaTeX-fill-break-before-code-comments |
2631 |
code-comment-flag |
code-comment-start |
2632 |
(> (- (line-end-position) (line-beginning-position)) |
(> (- (line-end-position) (line-beginning-position)) |
2633 |
fill-column)) |
fill-column)) |
2634 |
(beginning-of-line) |
(beginning-of-line) |
2635 |
(re-search-forward comment-start-skip (line-end-position) t) |
(goto-char end-marker) |
|
(goto-char (match-beginning 0)) |
|
2636 |
(while (not (looking-at TeX-comment-start-regexp)) (forward-char)) |
(while (not (looking-at TeX-comment-start-regexp)) (forward-char)) |
2637 |
(skip-chars-backward " \t") |
(skip-chars-backward " \t") |
2638 |
(skip-chars-backward "^ \t\n") |
(skip-chars-backward "^ \t\n") |
2766 |
;; handled with `fill-nobreak-predicate', but this is not available |
;; handled with `fill-nobreak-predicate', but this is not available |
2767 |
;; in XEmacs. |
;; in XEmacs. |
2768 |
(let ((final-breakpoint (point)) |
(let ((final-breakpoint (point)) |
2769 |
(verb-macros (regexp-opt LaTeX-verbatim-macros))) |
(verb-macros (regexp-opt LaTeX-verbatim-macros-with-delims))) |
2770 |
(save-excursion |
(save-excursion |
2771 |
(when (and (re-search-backward |
(when (and (re-search-backward |
2772 |
(concat (regexp-quote TeX-esc) "\\(?:" verb-macros |
(concat (regexp-quote TeX-esc) "\\(?:" verb-macros |
2939 |
(run-hooks 'LaTeX-fill-newline-hook)) |
(run-hooks 'LaTeX-fill-newline-hook)) |
2940 |
|
|
2941 |
(defun LaTeX-fill-paragraph (&optional justify) |
(defun LaTeX-fill-paragraph (&optional justify) |
2942 |
"Like \\[fill-paragraph], but handle LaTeX comments. |
"Like `fill-paragraph', but handle LaTeX comments. |
2943 |
If any of the current line is a comment, fill the comment or the |
If any of the current line is a comment, fill the comment or the |
2944 |
paragraph of it that point is in. Code comments, i.e. comments |
paragraph of it that point is in. Code comments, i.e. comments |
2945 |
with uncommented code preceding them in the same line, will not |
with uncommented code preceding them in the same line, will not |
2959 |
has-comment |
has-comment |
2960 |
;; Non-nil if the current line contains code and a comment. |
;; Non-nil if the current line contains code and a comment. |
2961 |
has-code-and-comment |
has-code-and-comment |
2962 |
|
code-comment-start |
2963 |
;; If has-comment, the appropriate fill-prefix for the comment. |
;; If has-comment, the appropriate fill-prefix for the comment. |
2964 |
comment-fill-prefix) |
comment-fill-prefix) |
2965 |
|
|
2966 |
;; Figure out what kind of comment we are looking at. |
;; Figure out what kind of comment we are looking at. |
2967 |
(save-excursion |
(cond |
2968 |
(beginning-of-line) |
;; A line only with potential whitespace followed by a |
2969 |
(cond |
;; comment on it? |
2970 |
;; A line only with potential whitespace followed by a |
((save-excursion |
2971 |
;; comment on it? |
(beginning-of-line) |
2972 |
((looking-at (concat "^[ \t]*" TeX-comment-start-regexp |
(looking-at (concat "^[ \t]*" TeX-comment-start-regexp |
2973 |
"\\(" TeX-comment-start-regexp "\\|[ \t]\\)*")) |
"\\(" TeX-comment-start-regexp "\\|[ \t]\\)*"))) |
2974 |
(setq has-comment t |
(setq has-comment t |
2975 |
comment-fill-prefix (buffer-substring (match-beginning 0) |
comment-fill-prefix (buffer-substring-no-properties |
2976 |
(match-end 0)))) |
(match-beginning 0) (match-end 0)))) |
2977 |
;; A line with some code, followed by a comment? |
;; A line with some code, followed by a comment? |
2978 |
((and (re-search-forward comment-start-skip (line-end-position) t) |
((and (setq code-comment-start (save-excursion |
2979 |
;; Don't treat trailing comment starters as code comments. |
(beginning-of-line) |
2980 |
(not (looking-at "$")) |
(LaTeX-search-forward-comment-start |
2981 |
|
(line-end-position)))) |
2982 |
|
(> (point) code-comment-start) |
2983 |
|
(not (TeX-in-commented-line)) |
2984 |
|
(save-excursion |
2985 |
|
(goto-char code-comment-start) |
2986 |
;; See if there is at least one non-whitespace character |
;; See if there is at least one non-whitespace character |
2987 |
;; before the comment starts. |
;; before the comment starts. |
2988 |
(re-search-backward "[^ \t\n]" (line-beginning-position) t)) |
(re-search-backward "[^ \t\n]" (line-beginning-position) t))) |
2989 |
(setq has-comment t |
(setq has-comment t |
2990 |
has-code-and-comment t)))) |
has-code-and-comment t))) |
2991 |
|
|
2992 |
(cond |
(cond |
2993 |
;; Code comments. |
;; Code comments. |
2994 |
((and has-code-and-comment |
(has-code-and-comment |
|
(not (TeX-in-commented-line))) |
|
2995 |
(save-excursion |
(save-excursion |
2996 |
(when (save-excursion |
(when (>= (- code-comment-start (line-beginning-position)) |
2997 |
;; Find the start of the comment. |
fill-column) |
2998 |
(beginning-of-line) |
;; If start of code comment is beyond fill column, fill it as a |
2999 |
(re-search-forward comment-start-skip (line-end-position) t) |
;; regular paragraph before it is filled as a code comment. |
|
(goto-char (match-beginning 0)) |
|
|
(while (not (looking-at TeX-comment-start-regexp)) |
|
|
(forward-char)) |
|
|
;; Is it beyond the fill column? |
|
|
(>= (- (point) (line-beginning-position)) fill-column)) |
|
|
;; Then fill it as a regular paragraph before it is filled |
|
|
;; as a code comment. |
|
3000 |
(let ((end-marker (save-excursion (end-of-line) (point-marker)))) |
(let ((end-marker (save-excursion (end-of-line) (point-marker)))) |
3001 |
(LaTeX-fill-region-as-paragraph (line-beginning-position) |
(LaTeX-fill-region-as-paragraph (line-beginning-position) |
3002 |
(line-beginning-position 2) |
(line-beginning-position 2) |
3084 |
(defun LaTeX-fill-code-comment (&optional justify-flag) |
(defun LaTeX-fill-code-comment (&optional justify-flag) |
3085 |
"Fill a line including code followed by a comment." |
"Fill a line including code followed by a comment." |
3086 |
(let ((beg (line-beginning-position)) |
(let ((beg (line-beginning-position)) |
3087 |
fill-prefix) |
fill-prefix code-comment-start) |
3088 |
(indent-according-to-mode) |
(indent-according-to-mode) |
3089 |
(when (when (re-search-forward comment-start-skip (line-end-position) t) |
(when (when (setq code-comment-start (save-excursion |
3090 |
(goto-char (match-beginning 0)) |
(goto-char beg) |
3091 |
|
(LaTeX-search-forward-comment-start |
3092 |
|
(line-end-position)))) |
3093 |
|
(goto-char code-comment-start) |
3094 |
(while (not (looking-at TeX-comment-start-regexp)) (forward-char)) |
(while (not (looking-at TeX-comment-start-regexp)) (forward-char)) |
3095 |
;; See if there is at least one non-whitespace character |
;; See if there is at least one non-whitespace character |
3096 |
;; before the comment starts. |
;; before the comment starts. |
3442 |
0)))))) |
0)))))) |
3443 |
(beginning-of-line))))) |
(beginning-of-line))))) |
3444 |
|
|
3445 |
|
(defun LaTeX-search-forward-comment-start (&optional limit) |
3446 |
|
"Search forward for a comment start from current position till LIMIT. |
3447 |
|
If LIMIT is omitted, search till the end of the buffer. |
3448 |
|
|
3449 |
|
This function makes sure that any comment starters found inside |
3450 |
|
of verbatim constructs are not considered." |
3451 |
|
(setq limit (or limit (point-max))) |
3452 |
|
(save-excursion |
3453 |
|
(catch 'found |
3454 |
|
(while (progn |
3455 |
|
(when (and (TeX-re-search-forward-unescaped |
3456 |
|
TeX-comment-start-regexp limit 'move) |
3457 |
|
(not (LaTeX-verbatim-p))) |
3458 |
|
(throw 'found t)) |
3459 |
|
(< (point) limit)))) |
3460 |
|
(unless (= (point) limit) (match-beginning 0)))) |
3461 |
|
|
3462 |
|
|
3463 |
;;; Math Minor Mode |
;;; Math Minor Mode |
3464 |
|
|