all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Fix RefTeX to show table of contents for dtx files
@ 2016-12-30 10:49 Sašo Živanović
  2017-01-02 12:22 ` Tassilo Horn
  0 siblings, 1 reply; 3+ messages in thread
From: Sašo Živanović @ 2016-12-30 10:49 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 925 bytes --]

I've fixed a tiny bug in RefTeX: TOC was not shown for dtx files.

Dtx files mix code and documentation. Any comment with the comment 
character at the beginning of the line is considered a part of the docs.

The regexp gathering sections allowed only whitespace before the section 
command. I've changed this so that now, the comment character is also 
allowed at the very beginning. In the parser code, I've added a filter 
that accepts only commented lines for dtx files and only uncommented 
ones for other files.

I've relied on the file name (ending in ".dtx", obviously), to detect 
dtx files. Using the major mode (doctex-mode or not) of the file that is 
currently visited does not work, as a tex file can input a dtx file, or 
vice versa. Maybe there's a way to also check file variables of included 
files, but I don't know about it, and it would probably be an overkill, 
anyway.

Best,
Sašo

[-- Attachment #2: 0001-Fix-RefTeX-to-show-table-of-contents-for-dtx-files.patch --]
[-- Type: text/x-patch, Size: 2286 bytes --]

From 76af298a47147e7b6db38b0228b19748ccf08633 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sa=C5=A1o=20=C5=BDivanovi=C4=87?=
 <saso.zivanovic@guest.arnes.si>
Date: Fri, 30 Dec 2016 11:12:42 +0100
Subject: [PATCH] Fix RefTeX to show table of contents for dtx files

* lisp/textmodes/reftex.el (reftex-compile-variables): Change the
  section regexp so that it accepts lines starting with the comment
  character.
* lisp/textmodes/reftex-parse.el (reftex-parse-from-file): Filter
  gathered toc entries, accepting a commented entry if and only if the
  source file is a ".dtx" file.
---
 lisp/textmodes/reftex-parse.el | 6 +++++-
 lisp/textmodes/reftex.el       | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 9180bea..1c628c6 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -270,7 +270,11 @@ of master file."
 		 (when (eq (char-before) ?\\) (backward-char))
                  ;; Insert in List
                  (setq toc-entry (funcall reftex-section-info-function file))
-                 (when toc-entry
+                 (when (and toc-entry
+                            (equal
+                             (equal (char-after bound) ?%)
+                             (string-suffix-p ".dtx" file)
+                             ))
                    ;; It can happen that section info returns nil
                    (setq level (nth 5 toc-entry))
                    (setq highest-level (min highest-level level))
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index adc5076..c309f3e 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -1015,8 +1015,8 @@ This enforces rescanning the buffer on next use."
     ;; Calculate the regular expressions
     (let* (
 ;          (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
-           (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because
-                                  ; match numbers are hard coded
+           (wbol "\\(^\\)%?[ \t]*") ; Need to keep the empty group because
+                                    ; match numbers are hard coded
            (label-re (concat "\\(?:"
 			     (mapconcat 'identity reftex-label-regexps "\\|")
 			     "\\)"))
-- 
2.10.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix RefTeX to show table of contents for dtx files
  2016-12-30 10:49 [PATCH] Fix RefTeX to show table of contents for dtx files Sašo Živanović
@ 2017-01-02 12:22 ` Tassilo Horn
  2017-01-02 15:41   ` Sašo Živanović
  0 siblings, 1 reply; 3+ messages in thread
From: Tassilo Horn @ 2017-01-02 12:22 UTC (permalink / raw)
  To: Sašo Živanović; +Cc: emacs-devel

Sašo Živanović <saso.zivanovic@guest.arnes.si> writes:

Hi Sašo,

> I've fixed a tiny bug in RefTeX: TOC was not shown for dtx files.

Good catch, thanks!

I've committed your patch with a slight modification.  Instead of this

> -                 (when toc-entry
> +                 (when (and toc-entry
> +                            (equal
> +                             (equal (char-after bound) ?%)
> +                             (string-suffix-p ".dtx" file)
> +                             ))

I used

                   (when (and toc-entry
                            (eq ;; Either both are t or both are nil.
                             (= (char-after bound) ?%)
                             (string-suffix-p ".dtx" file)))

which looks a bit more clear to me.

I've seen that this is your first patch to Emacs, and given that it's
less than 15 lines of code, I can commit it for you as-is.  However, if
you plan to contribute more in the future, a copyright assignment will
be due.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix RefTeX to show table of contents for dtx files
  2017-01-02 12:22 ` Tassilo Horn
@ 2017-01-02 15:41   ` Sašo Živanović
  0 siblings, 0 replies; 3+ messages in thread
From: Sašo Živanović @ 2017-01-02 15:41 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

Hi Tassilo!

Thanks for the prompt reply and commit!

On 02. 01. 2017 13:22, Tassilo Horn wrote:
> Sašo Živanović <saso.zivanovic@guest.arnes.si> writes:
>
> Hi Sašo,
>
>> I've fixed a tiny bug in RefTeX: TOC was not shown for dtx files.
>
> Good catch, thanks!
>
> I've committed your patch with a slight modification.  Instead of this
>
>> -                 (when toc-entry
>> +                 (when (and toc-entry
>> +                            (equal
>> +                             (equal (char-after bound) ?%)
>> +                             (string-suffix-p ".dtx" file)
>> +                             ))
>
> I used
>
>                    (when (and toc-entry
>                             (eq ;; Either both are t or both are nil.
>                              (= (char-after bound) ?%)
>                              (string-suffix-p ".dtx" file)))
>
> which looks a bit more clear to me.
Fine with me. You see that my lisp is pretty rudimentary ...

>
> I've seen that this is your first patch to Emacs, and given that it's
> less than 15 lines of code, I can commit it for you as-is.  However, if
> you plan to contribute more in the future, a copyright assignment will
> be due.
Gladly.

Best,
Sašo

>
> Bye,
> Tassilo
>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-02 15:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-30 10:49 [PATCH] Fix RefTeX to show table of contents for dtx files Sašo Živanović
2017-01-02 12:22 ` Tassilo Horn
2017-01-02 15:41   ` Sašo Živanović

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.