[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] manipulating sections with auc-tex
From: |
Matthieu Moy |
Subject: |
Re: [AUCTeX] manipulating sections with auc-tex |
Date: |
Mon, 22 Aug 2005 22:58:11 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
Ralf Angeli <address@hidden> writes:
> Would you like to prepare a patch against latex.el which accomplishes
> what we've discussed so far?
I've started adapting my code to include it in latex.el. The patch
follows for info.
However, I wonder if a simple
(defun LaTeX-mark-section (point)
"Select entire section (and subsections) in a LaTeX document."
(interactive "d")
(goto-char point)
(outline-mark-subtree)
(TeX-activate-region))
Wouldn't be sufficient.
> We will need a copyright assignment from you in case you haven't
> signed one for AUCTeX so far.
Well, if you choose the outline-mark-subtree, I'll not bother the FSF
with copyright assignment since this is trivial code. Tell me what you
prefer.
--
Matthieu
diff -ur auctex.orig/latex.el auctex/latex.el
--- auctex.orig/latex.el 2005-08-22 21:15:14.000000000 +0200
+++ auctex/latex.el 2005-08-22 22:43:29.000000000 +0200
@@ -197,6 +197,32 @@
("subparagraph" 6))
"List which elements is the names of the sections used by LaTeX.")
+(defun LaTeX-section-list-level (level &optional list)
+ "List of sections with level lower or equal to LEVEL (a string).
+
+LIST is `LaTeX-section-list' by default, and must have the same format."
+ (let ((list (or list LaTeX-section-list)))
+ (if (or (null level) (string= level (caar list)))
+ list
+ (let ((rest (cdr list)))
+ (if rest
+ (LaTeX-section-list-level level rest)
+ (error "\"%s\" is not a section name." level))))))
+
+(defun LaTeX-section-list-level-higher (level &optional list)
+ "List of sections with level higher or equal to LEVEL (a string).
+
+LIST is `LaTeX-section-list' by default, and must have the same
+format."
+ (let ((list (or list LaTeX-section-list)))
+ (if (string= level (caar list))
+ (list (car list))
+ (let ((rest (cdr list)))
+ (if rest
+ (cons (car list)
+ (LaTeX-section-list-level-higher level rest))
+ (error "\"%s\" is not a section name." level))))))
+
(defun LaTeX-section-name (level)
"Return the name of the section corresponding to LEVEL."
(let ((entry (TeX-member level LaTeX-section-list
@@ -224,8 +250,8 @@
:type '(repeat (group (regexp :tag "Match")
(integer :tag "Level"))))
-(defun LaTeX-outline-regexp (&optional anywhere)
- "Return regexp for LaTeX sections.
+(defun LaTeX-outline-regexp (&optional anywhere level)
+ "Return regexp for LaTeX sections with level lower than LEVEL.
If optional argument ANYWHERE is not nil, do not require that the
header is at the start of a line."
@@ -233,7 +259,27 @@
"[ \t]*"
(regexp-quote TeX-esc)
"\\(appendix\\|documentstyle\\|documentclass\\|"
- (mapconcat 'car LaTeX-section-list "\\|")
+ (regexp-opt (mapcar 'car (LaTeX-section-list-level
+ level)))
+ "\\)\\b"
+ (if TeX-outline-extra
+ "\\|"
+ "")
+ (mapconcat 'car TeX-outline-extra "\\|")
+ "\\|" TeX-header-end
+ "\\|" TeX-trailer-start))
+
+(defun LaTeX-outline-regexp-higher (&optional anywhere level)
+ "Return regexp for LaTeX sections with level higher than LEVEL.
+
+If optional argument ANYWHERE is not nil, do not require that the
+header is at the start of a line."
+ (concat (if anywhere "" "^")
+ "[ \t]*"
+ (regexp-quote TeX-esc)
+ "\\(appendix\\|documentstyle\\|documentclass\\|"
+ (regexp-opt (mapcar 'car (LaTeX-section-list-level-higher
+ level)))
"\\)\\b"
(if TeX-outline-extra
"\\|"
@@ -3045,16 +3091,35 @@
(LaTeX-fill-region (region-beginning) (region-end) justify
(concat " section " (TeX-match-buffer 1)))))
-(defun LaTeX-mark-section ()
- "Set mark at end of current logical section, and point at top."
- (interactive)
- (re-search-forward (concat "\\(" (LaTeX-outline-regexp)
- "\\|\\'\\)"))
- (re-search-backward "^")
- (set-mark (point))
- (re-search-backward (concat "\\(" (LaTeX-outline-regexp)
- "\\|\\`\\)"))
- (TeX-activate-region))
+(defun LaTeX-outline-find-section (point)
+ "Find begining and end of current section.
+
+Return a pair (begin end) of points."
+ (save-excursion
+ (goto-char point)
+ (end-of-line)
+ (re-search-backward (concat "\\(" (LaTeX-outline-regexp)
+ "\\|\\`\\)"))
+ (let* ((begin (point))
+ (level (substring (match-string 1) 1)))
+ (message level)
+ (forward-line 1)
+ (or (re-search-forward (LaTeX-outline-regexp-higher t level) nil t)
+ (goto-char (point-max)))
+ (forward-line -1)
+ (tla--trace-current-line)
+ (end-of-line)
+ (list begin (point)))))
+
+(defun LaTeX-mark-section (point)
+ "Select entire section (and subsections) in a LaTeX document."
+ (interactive "d")
+ (let* ((pair (LaTeX-outline-find-section point))
+ (begin (car pair))
+ (end (cadr pair)))
+ (goto-char begin)
+ (set-mark end)
+ (TeX-activate-region)))
(defun LaTeX-fill-buffer (justify)
"Fill and indent current buffer as LaTeX text."
Only in auctex: latex.el~
- [AUCTeX] manipulating sections with auc-tex, Matthieu Moy, 2005/08/15
- Re: [AUCTeX] manipulating sections with auc-tex, Ralf Angeli, 2005/08/17
- Re: [AUCTeX] manipulating sections with auc-tex, Matthieu Moy, 2005/08/17
- Re: [AUCTeX] manipulating sections with auc-tex, Ralf Angeli, 2005/08/19
- Re: [AUCTeX] manipulating sections with auc-tex, David Kastrup, 2005/08/19
- Re: [AUCTeX] manipulating sections with auc-tex,
Matthieu Moy <=
- Re: [AUCTeX] manipulating sections with auc-tex, Ralf Angeli, 2005/08/23
- Re: [AUCTeX] manipulating sections with auc-tex, David Kastrup, 2005/08/23
- Re: [AUCTeX] manipulating sections with auc-tex, Ralf Angeli, 2005/08/23
- Re: [AUCTeX] manipulating sections with auc-tex, David Kastrup, 2005/08/23
- Re: [AUCTeX] manipulating sections with auc-tex, Ralf Angeli, 2005/08/24
- Re: [AUCTeX] manipulating sections with auc-tex, Matthieu Moy, 2005/08/23
- Re: [AUCTeX] manipulating sections with auc-tex, Ralf Angeli, 2005/08/23
- Re: [AUCTeX] manipulating sections with auc-tex, Matthieu Moy, 2005/08/23
- Re: [AUCTeX] manipulating sections with auc-tex, Matthieu Moy, 2005/08/26
- Re: [AUCTeX] manipulating sections with auc-tex, Ralf Angeli, 2005/08/26