auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-devel] Re: Contribution to AUCTeX


From: Vincent Belaïche
Subject: [AUCTeX-devel] Re: Contribution to AUCTeX
Date: Sat, 24 Jul 2010 20:42:02 +0200

Salut Ralf,

Answers embedded below.

> From: address@hidden
> To: address@hidden
> CC: address@hidden
> Subject: Re: Contribution to AUCTeX
> Date: Sat, 24 Jul 2010 16:40:02 +0200
>

[...]

>
> * no prefix argument: mark section including subsections
> * C-u: mark section without subsections
> * C-u C-u: mark node including subnodes
> * C-u C-u C-u: mark node without subnodes
>

I followed this recommendation except that there is no such thing as
"node without subnodes" that was not supported with the initial
implementation the mark-node aspect of which will just mark one single
node.

The reason for that is that subnodes are not necessarily consecutive,
although it is quite reasonable to think that a good Texinfo source code
would have them consecutive.

The new patch is attached.


> If you have two separate functions then you can use the prefix argument
> for the inclusion of subsections or subnodes only, which is much cleaner
> IMO.
>


[...]

>
> Anyhow, if you think the optimization is worth keeping, then keep it,
> but then please add a comment about why it was implemented like that
> instead of using a simple solution.
>

I added the comment rather than suppress the "obfuscating"
implementation: I feel it is usefull when you grep over an number of
texinfo files not to duplicate this string for each buffer, but as I
wrote it, if people prefer to have simpler code, then I am not that
strongly opinionated, nowadays machines are powerful enough not to
bother that much about this.

[...]

>
> --
> Ralf

No problem, anyhow don't expect any quick feedback during August, I will
switch off my PC to observe some rest period. Good luck with your
machine.

  Vincent.

*** tex-info.el.old     Mon Jul 12 19:44:31 2010
--- tex-info.el Sat Jul 24 18:26:23 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,67 ----
      ("verbatim") ("vtable"))
    "Alist of Texinfo environments.")
  
+ (defvar Texinfo-structuring-command-re nil
+   "Placeholder for regexp to match structuring commands.
+ This is done in order not to duplicate variable `outline-regexp'
+ memory footprint when several Texinfo buffers are edited.")
+ 
+ 
  (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 ****
--- 166,300 ----
          (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 no-subsection)
+   "Mark current section, with inclusion of any containing node.
+ 
+ The current section is detected as starting by any of the
+ structuring commands matched by regexp in variable
+ `outline-regexp' which in turn is a regexp matching any element
+ of variable `texinfo-section-list'.
+ 
+ If optional argument NO-SUBSECTION is set to any integer or is a
+ non nil empty argument (i.e. `C-u \\[Texinfo-mark-section]'),
+ then mark the current section without any subsection.
+ 
+ If optional argument NO-SUBSECTION is a double empty prefix
+ argument, (i.e. `C-u C-u \\[Texinfo-mark-section]') then mark
+ current node."
+   (interactive "P")
+   (let (beg end is-beg-section is-end-section)
+     (cond
+      ;; node
+      ((and (consp no-subsection)
+          (eq (car no-subsection) 16))
+       (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
+      ((or (integerp no-subsection)
+         (eq no-subsection '-)
+         (and (consp no-subsection) (eq (car no-subsection) 4)))
+       (setq beg (save-excursion
+                 (end-of-line)
+                 (re-search-backward (concat "^\\s-*" outline-regexp) nil t))
+           is-beg-section t
+           end
+           (save-excursion
+             (beginning-of-line)
+             (when
+                 (re-search-forward (concat "^\\s-*" outline-regexp
+                                            "\\|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 (concat "^\\s-*" outline-regexp) 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 "^\\s-*" outline-regexp
+                                                     "\\|address@hidden>" )
+                                             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 "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 ****
--- 366,373 ----
  
      ;; 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
***************
*** 383,393 ****
    (if (not (boundp 'texinfo-section-list))
        ;; This was included in 19.31.
        ()
!     (make-local-variable 'outline-regexp)
!     (setq outline-regexp
!         (concat "@\\("
!                 (mapconcat 'car texinfo-section-list "\\>\\|")
!                 "\\>\\)"))
      (make-local-variable 'outline-level)
      (setq outline-level 'texinfo-outline-level))
  
--- 520,548 ----
    (if (not (boundp 'texinfo-section-list))
        ;; This was included in 19.31.
        ()
!     ;; the reason why in the following we don't do simply the following code
!     ;;
!     ;; (set (make-local-variable 'outline-regexp)  (concat "@"
!     ;;                   (funcall 'regexp-opt
!     ;;                            (mapcar 'car texinfo-section-list)
!     ;;                            'words)))
!     ;;
!     ;; is that such a code would create as many instances of the regexp string
!     ;; as there are Texinfo buffers. In the likely case where the
!     ;; texinfo-section-list is the same for all instances of Texinfo buffers
!     ;; the following implementation will save the memory by having just one
!     ;; instance of the regexp string in memory.
!     (set (make-local-variable 'outline-regexp)
!        (let ((re (concat "@"
!                          (funcall 'regexp-opt
!                                   (mapcar 'car texinfo-section-list)
!                                   'words))))
!              (cond
!               ((null Texinfo-structuring-command-re)
!                (setq Texinfo-structuring-command-re re))
!               ((string= Texinfo-structuring-command-re re)
!                Texinfo-structuring-command-re)
!               (t re))))
      (make-local-variable 'outline-level)
      (setq outline-level 'texinfo-outline-level))
  

reply via email to

[Prev in Thread] Current Thread [Next in Thread]