auctex-devel
[Top][All Lists]
Advanced

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

Re: [AUCTeX-devel] Texinfo: mark environment and mark section/node


From: Vincent Belaïche
Subject: Re: [AUCTeX-devel] Texinfo: mark environment and mark section/node
Date: Mon, 20 Jun 2011 10:43:26 +0200

Ooooooooooooooooooooooooops...

Thank you for pointing that out. Here are the updated changelog and patch.

I have re-tested only the mark section as I've not changed any else
since my last message.

Hopefully, we finally converge!

   Vincent.

-----------------------------------------------------------------------
2011-06-20  Vincent Belaïche  <address@hidden>

        * tex-info.el (Texinfo-mark-environment, Texinfo-mark-section)
        (Texinfo-mark-node): New defun.
        (Texinfo-mode-map): added key bindings for
        Texinfo-mark-environment, Texinfo-mark-section, and
        Texinfo-mark-node.
-----------------------------------------------------------------------

*** tex-info.el.~5.161~ Mon Jun 20 08:35:57 2011
--- tex-info.el Mon Jun 20 08:32:46 2011
***************
*** 160,165 ****
--- 160,293 ----
          (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 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
+           (section-re (concat "^\\s-*" outline-regexp)))
+     (if (and (consp no-subsection) (eq (car no-subsection) 4))
+       ;; section with exclusion of any subsection
+       (setq beg (save-excursion
+                   (unless (looking-at section-re)
+                     (end-of-line))
+                   (re-search-backward section-re nil t))
+             is-beg-section t
+             end (save-excursion
+                   (beginning-of-line)
+                   (when
+                       (re-search-forward (concat section-re
+                                                  "\\|address@hidden>" ) nil t)
+                     (save-match-data
+                       (beginning-of-line)
+                       (point))))
+             is-end-section (match-string 1))
+       ;; full section without exclusion of any subsection
+       (let (section-command-level)
+       (setq beg
+             (save-excursion
+               (end-of-line)
+               (re-search-backward section-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 section-re
+                                                     "\\|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)))))));  (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 "address@hidden>")
+             (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 address@hidden' and ending at next
+ beginning of keyword address@hidden' or address@hidden'."
+   (interactive)
+   (let ((beg (save-excursion
+              (unless (looking-at "address@hidden(?:node\\)\\_>")
+                (end-of-line))
+              (re-search-backward "address@hidden(?:node\\)\\_>" nil t )))
+       (end (save-excursion
+              (beginning-of-line)
+              (and (re-search-forward "address@hidden(?: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 address@hidden' and prompt for current,
***************
*** 231,236 ****
--- 359,367 ----
  
      ;; 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"   'address@hidden)
      (or (key-binding "\e\r")
        (define-key map "\e\r" 'address@hidden)) ;*** Alias

reply via email to

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