[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX] Texinfo: mark environment and mark section/node
From: |
Vincent Belaïche |
Subject: |
[AUCTeX] Texinfo: mark environment and mark section/node |
Date: |
Tue, 17 May 2011 06:49:54 +0200 |
Hello Ralf,
Quite some time ago I had submitted a contribution to have mark
environment and mark section commands for Texinfo also. I made an update
of AUCTeX recently and I realized that they are still not in the CVS
tree...
I attach again the patch made at that time, but certainly the diff was
relative to some outdated version of tex-info.el.
Sorry, but I do not remember what was the outcome of discussion that we
had at that time. I rememeber that you questionned the use of `C-c .'
and `C-c *' keybindings, but I thought that my contribution was fine all
the same because no alternative keybinding was proposed.
VBR,
Vincent.
PS: The assignment was `Belaïche RT: 463852' of 2009-12-03, so from a
legal point of view I did it through.
*** tex-info.el.old Sun Jun 13 04:54:51 2010
--- c:/Programme/GNU/emacs-extension/lisp/auctex/tex-info.el Sun Jun 13
05:31:02 2010
***************
*** 52,61 ****
("verbatim") ("vtable"))
"Alist of Texinfo environments.")
(defconst texinfo-environment-regexp
;; Overwrite version from `texinfo.el'.
(concat "address@hidden("
! (mapconcat 'car Texinfo-environment-list "\\|")
"\\|end\\)\\>")
"Regexp for environment-like Texinfo list commands.
Subexpression 1 is what goes into the corresponding address@hidden'
statement.")
--- 52,79 ----
("verbatim") ("vtable"))
"Alist of Texinfo environments.")
+
+ (defconst Texinfo-structuring-command-levels-alist
+ '( ("top" . -1) ("chapter" . 0) ("unnumbered" . 0) ("appendix" . 0)
+ ("majorheading" . 2) ("chapheading" . 2)
+ ("section" . 5) ("unnumberedsec" . 5) ("appendixsec" . 5) ("heading" . 5)
+ ("subsection" . 9) ("unnumberedsubsec" . 9) ("appendixsubsec" . 9)
("subheading" . 9)
+ ("subsubsection" . 13))
+ "Alist providing for each strucuting command the corresponding
+ level starting by -1 for @top, down to 13 for @subsubsection." )
+
+
+ (defconst Texinfo-structuring-command-re
+ (concat "^\\s-*@"
+ (funcall 'regexp-opt (mapcar 'car
Texinfo-structuring-command-levels-alist)
+ 'word))
+ "Regexp to match structuring commands")
+
+
(defconst texinfo-environment-regexp
;; Overwrite version from `texinfo.el'.
(concat "address@hidden("
! (regexp-opt (mapcar 'car Texinfo-environment-list))
"\\|end\\)\\>")
"Regexp for environment-like Texinfo list commands.
Subexpression 1 is what goes into the corresponding address@hidden'
statement.")
***************
*** 160,165 ****
--- 178,301 ----
(goto-char (match-beginning 0))
(error "Can't locate start of current environment")))))
+
+
+ (defun Texinfo-mark-environment (&optional count)
+ "Set mark to end of current environment and point to the matching begin.
+ If prefix argument COUNT is given, mark the respective number of
+ enclosing environments. The command will not work properly if
+ there are unbalanced begin-end pairs in comments and verbatim
+ environments."
+ ;; TODO:
+ ;; This is identical to the LaTeX counterpart but for the find begin/end
+ ;; functions. So some day the implemenation should be factorized.
+ (interactive "p")
+ (setq count (if count (abs count) 1))
+ (let ((cur (point)) beg end)
+ ;; Only change point and mark after beginning and end were found.
+ ;; Point should not end up in the middle of nowhere if the search fails.
+ (save-excursion
+ (dotimes (c count)
+ (Texinfo-find-env-end))
+ (setq end (line-beginning-position 2))
+ (goto-char cur)
+ (dotimes (c count)
+ (Texinfo-find-env-start)
+ (unless (= (1+ c) count)
+ (beginning-of-line 0)))
+ (setq beg (point)))
+ (set-mark end)
+ (goto-char beg)
+ (TeX-activate-region)))
+
+
+ (defun Texinfo-mark-section (&optional to-be-marked)
+ "Mark current section, with inclusion of any containing to-be-marked,
+ where current section is started by any of the structuring
+ commands matched by regexp in constant
+ `Texinfo-structuring-command-re'.
+
+ If optional argument TO-BE-MARKED is set to 1 or is a non nil empty
+ argument, then mark current node.
+
+ If optional argument TO-BE-MARKED is set to 2 or to `-', then
+ mark current section, with exclusion of any subsections."
+ (interactive "P")
+ (let (beg end is-beg-section is-end-section)
+ (cond
+ ;; node
+ ((or (eq to-be-marked 1) (and (consp to-be-marked) (eq (car
to-be-marked) 4)))
+ (setq beg
+ (save-excursion
+ (end-of-line)
+ (re-search-backward "address@hidden>" nil t ))
+ end
+ (save-excursion
+ (beginning-of-line)
+ (when
+ (re-search-forward "address@hidden(?:node\\|bye\\)\\_>" nil t
)
+ (beginning-of-line)
+ (point)))))
+ ;; section with exclusion of any subsection
+ ((memq to-be-marked '(- 2))
+ (setq beg (save-excursion
+ (end-of-line)
+ (re-search-backward Texinfo-structuring-command-re nil t))
+ is-beg-section t
+ end
+ (save-excursion
+ (beginning-of-line)
+ (when
+ (re-search-forward (concat Texinfo-structuring-command-re
+ "\\|address@hidden>" ) nil t)
+ (save-match-data
+ (beginning-of-line)
+ (point))))
+ is-end-section (match-string 1)))
+ ;;
+ (t
+ (let (section-command-level)
+ (setq beg
+ (save-excursion
+ (end-of-line)
+ (re-search-backward Texinfo-structuring-command-re nil t)))
+ (when beg
+ (setq is-beg-section t
+ section-command-level
+ (cdr (assoc (match-string 1)
Texinfo-structuring-command-levels-alist))
+ end
+ (save-excursion
+ (beginning-of-line)
+ (while
+ (and (re-search-forward (concat
Texinfo-structuring-command-re
+ "\\|address@hidden>" )
nil t)
+ (or
+ (null (setq is-end-section (match-string 1)))
+ (> (cdr (assoc is-end-section
Texinfo-structuring-command-levels-alist))
+ section-command-level))))
+ (when (match-string 0)
+ (beginning-of-line)
+ (point)))))))); (cond ...)
+ (when (and beg end)
+ ;; now take also enclosing node of beg and end
+ (dolist
+ (boundary '(beg end))
+ (when (symbol-value (intern (concat "is-" (symbol-name boundary)
"-section")))
+ (save-excursion
+ (goto-char (symbol-value boundary))
+ (while
+ (and
+ (null (bobp))
+ (progn
+ (beginning-of-line 0)
+ (looking-at "^\\s-*\\($\\|@\\(c\\|comment\\)\\_>\\)"))))
+ (when (looking-at "address@hidden>")
+ (set boundary (point))))))
+
+ (set-mark end)
+ (goto-char beg)
+ (TeX-activate-region) )))
+
(defun Texinfo-insert-node ()
"Insert a Texinfo node in the current buffer.
That means, insert the string address@hidden' and prompt for current,
***************
*** 231,236 ****
--- 367,374 ----
;; Simulating LaTeX-mode
(define-key map "\C-c\C-e" 'Texinfo-environment)
+ (define-key map "\C-c." 'Texinfo-mark-environment)
+ (define-key map "\C-c*" 'Texinfo-mark-section)
(define-key map "\C-c\n" 'address@hidden)
(or (key-binding "\e\r")
(define-key map "\e\r" 'address@hidden)) ;*** Alias
- [AUCTeX] Texinfo: mark environment and mark section/node,
Vincent Belaïche <=