[...]

>
>Looking at the last messages in the discussion we had, the main issue I
>still had with the patch was that `Texinfo-mark-section' marks both
>sections and nodes. It would be better if there were two separate
>functions for these functionalities.
>
>-- 
>Ralf

Salut Ralf & AUCTeX-devel,

This email contains a novel patch where node & sections are marked by
different functions.

I will provide a corresponding patch to documentation after this one is
accepted.

Here is the changelog:

-----------------------------------------------------------------------
2011-05-30  Vincent Belaïche  <[email protected]>

        * tex-info.el (Texinfo-mark-environment, Texinfo-mark-section)
        (Texinfo-mark-node): New defun.
        (Texinfo-structuring-command-levels-alist)
        (Texinfo-structuring-command-re): new defconst.
        (Texinfo-mode-map): added key bindings for
        Texinfo-mark-environment, Texinfo-mark-section, and
        Texinfo-mark-node.
-----------------------------------------------------------------------

And here follows the patch...

   Vincent.

*** tex-info.el.~5.161~	Mon May 30 19:40:47 2011
--- tex-info.el	Mon May 30 19:46:31 2011
***************
*** 52,57 ****
--- 52,74 ----
      ("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 level for each strucuting command.  \
+ The associated level is 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 "^@\\("
***************
*** 160,165 ****
--- 177,306 ----
  	  (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 exclude-sub)
+   "Mark current section.  \
+ Current section is started by any of
+ the structuring commands matched by regexp in constant
+ `Texinfo-structuring-command-re'.
+ 
+ If optional argument EXCLUDE-SUB is passed as `C-u
+ \\[Texinfo-mark-section]', mark current section, with exclusion
+ of any subsections.
+ 
+ Otherwise, any included subsections are also marked along with current section.
+ 
+ Note that when current section is starting immediatley after a
+ node commande, then the node command is also marked as part as the section."
+   (interactive "P")
+   (let (beg end is-beg-section is-end-section)
+     (if (and (consp exclude-sub) (eq (car exclude-sub) 4))
+ 	;; section with exclusion of any subsection
+ 	(setq beg (save-excursion
+ 		    (unless (looking-at Texinfo-structuring-command-re)
+ 		      (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
+ 						   "\\|^\\s-*@bye\\_>" ) nil t)
+ 		      (save-match-data
+ 			(beginning-of-line)
+ 			(point))))
+ 	      is-end-section (match-string 1)))
+     ;;
+     (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
+ 						    "\\|^\\s-*@bye\\_>" ) 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))))));  (if ...)
+     (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 "^\\s-*@node\\_>")
+ 	      (set boundary (point))))))
+ 
+       (set-mark end)
+       (goto-char beg)
+       (TeX-activate-region) )))
+ 
+ (defun Texinfo-mark-node ()
+   "Mark the current node.  \
+ This is the node in which the pointer is.  It is starting at
+ previous beginning of keyword `@node' and ending at next
+ beginning of keyword `@node' or `@bye'."
+   (interactive)
+   (let ((beg (save-excursion
+ 	       (unless (looking-at "^\\s-*@\\(?:node\\)\\_>")
+ 		 (end-of-line))
+ 	       (re-search-backward "^\\s-*@\\(?:node\\)\\_>" nil t )))
+ 	(end (save-excursion
+ 	       (beginning-of-line)
+ 	       (and (re-search-forward "^\\s-*@\\(?:node\\|bye\\)\\_>" nil t )
+ 		    (progn (beginning-of-line) (point))))))
+ 
+     (when (and beg end)
+       (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 `@node' and prompt for current,
***************
*** 231,236 ****
--- 372,380 ----
  
      ;; 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 "\M-\C-h" 'Texinfo-mark-node)
      (define-key map "\C-c\n"   'texinfo-insert-@item)
      (or (key-binding "\e\r")
  	(define-key map "\e\r" 'texinfo-insert-@item)) ;*** Alias
_______________________________________________
auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex

Reply via email to