Dear Ralf,

The reason why there is this new variable is simply that I completely
missed the fact that this was already existing. I had looked only into
Texinfo, and I forgot to look out also in the native texinfo.

I provide hereinattached a corrected patch with a ChangeLog.

I also acknowledge the fact that there should be only one feature per
patch and not 3 like this:

1. optimization of texinfo-environment-regexp (use of regexp-opt)

2. Addition of environment mark function

3. Addition of section mark function.


I can split this into 3 differents/subsequent contributions with
respective ChangeLog -- or not, it is up to your feedback.

If you want 3 separate patches, then could you please tell me in which
order I should provide them.

BR,
   Vincent.

PS: please remember I am not subscribed to the devel list, explicitely
include me for answer.


> From: ang...@caeruleus.net
> To: vincent....@hotmail.fr
> CC: auctex-devel@gnu.org
> Subject: Re: Contribution to AUCTeX‏
> Date: Fri, 18 Jun 2010 17:44:51 +0200
>
> * Vincent Belaïche (2010-06-13) writes:
>
> > + (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." )
>
> Why is this constant required? tex-info.el has been using
> `texinfo-section-list' up until now which also includes information on
> sectioning levels.
>
> By the way, it would probably be easier if you included only one new
> feature per patch. (Including a ChangeLog entry!) Then we could
> already check it in once we discussed it and would not have to wait
> until we discussed the other features as well. (c:
>
> --
> Ralf
2010-06-03  Vincent Belaïche  <vincen...@users.sourceforge.net>

        * tex-info.el (Texinfo-mark-section): Creation of function
        (Texinfo-mark-environment): Creation of function
        (texinfo-environment-regexp): optimize by use of regexp-opt

*** c:/Programme/GNU/emacs-extension/lisp/old/tex-info.el.old	Mon Jun 21 20:13:52 2010
--- tex-info.el	Mon Jun 21 20:11:11 2010
***************
*** 52,61 ****
      ("verbatim") ("vtable")) 
    "Alist of Texinfo environments.")
  
  (defconst texinfo-environment-regexp
    ;; Overwrite version from `texinfo.el'.
    (concat "^...@\\("
! 	  (mapconcat 'car Texinfo-environment-list "\\|")
  	  "\\|end\\)\\>")
    "Regexp for environment-like Texinfo list commands.
  Subexpression 1 is what goes into the corresponding `...@end' statement.")
--- 52,68 ----
      ("verbatim") ("vtable")) 
    "Alist of Texinfo environments.")
  
+ (defconst Texinfo-structuring-command-re
+   (concat "^\\s-*@" 
+ 	  (funcall 'regexp-opt (mapcar 'car texinfo-section-list)
+ 	   'word))
+   "Regexp to  match structuring commands")
+   
+ 
  (defconst texinfo-environment-regexp
    ;; Overwrite version from `texinfo.el'.
    (concat "^...@\\("
! 	  (regexp-opt (mapcar 'car Texinfo-environment-list))
  	  "\\|end\\)\\>")
    "Regexp for environment-like Texinfo list commands.
  Subexpression 1 is what goes into the corresponding `...@end' statement.")
***************
*** 160,165 ****
--- 167,292 ----
  	  (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 "^\\...@node\\_>" nil t ))
+ 	    end
+ 	    (save-excursion
+ 	      (beginning-of-line)
+ 	      (when 
+ 		  (re-search-forward "^\\...@\\(?: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 
+ 					     "\\|^\\...@bye\\_>" ) 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  
+ 		(cadr (assoc (match-string 1) texinfo-section-list))
+ 		end 
+ 		(save-excursion
+ 		  (beginning-of-line)
+ 		  (while
+ 		      (and (re-search-forward (concat Texinfo-structuring-command-re 
+ 						      "\\|^\\...@bye\\_>" ) 
+ 					      nil t)
+                           (or
+                            (null (setq is-end-section  (match-string 1)))
+                            (> (cadr (assoc is-end-section 
+ 					  texinfo-section-list))
+                               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 "^\\...@node\\_>")
+ 	      (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 `...@node' and prompt for current,
***************
*** 231,236 ****
--- 358,365 ----
  
      ;; 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"   'texinfo-inse...@item)
      (or (key-binding "\e\r")
  	(define-key map "\e\r" 'texinfo-inse...@item)) ;*** Alias
_______________________________________________
auctex-devel mailing list
auctex-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to