unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* [21.3] [patch] M-x man does not pick word 'snmpd.conf(5)'
@ 2004-11-21 16:47 Jari Aalto
  2004-11-21 20:06 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Jari Aalto @ 2004-11-21 16:47 UTC (permalink / raw)



In GNU Emacs 21.3.1 (i386-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2004-10-16 on raven, modified by Debian
configured using `configure '--build=i386-linux' '--host=i386-linux' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--with-x=yes' '--with-x-toolkit=athena' 'CFLAGS=-DDEBIAN -g -O2' 'build_alias=i386-linux' 'host_alias=i386-linux''


Command M-x man and the call to (Man-default-man-entry) does not pick full
manual page reference like snmpd.conf(5).

Given cursor -!- positions:

   sn-!-mpd.conf(5)  => (Man-default-man-entry) => snmp
   snmpd.c-!-onf(5)  => (Man-default-man-entry) => conf(5)

Patch attached. Old defsubst was completely rewritten to take
use of the syntax table instead of relying forward-word etc.

Jari

2004-11-21  Jari Aalto  <jari aalto A T cante net>

	* man.el (Man-default-man-entry): Use local syntax
	table to get correct full word in cases like 'snmpd.conf(5)'.


--- man.el.orig	2004-11-21 18:05:53.000000000 +0200
+++ man.el	2004-11-21 18:45:26.000000000 +0200
@@ -502,23 +502,35 @@
 (defsubst Man-default-man-entry ()
   "Make a guess at a default manual entry.
 This guess is based on the text surrounding the cursor."
-  (let (word)
-    (save-excursion
       ;; Default man entry title is any word the cursor is on, or if
       ;; cursor not on a word, then nearest preceding word.
+  ;; Use local syntax table to find correct word in cases like:
+  ;;    ioctl(2) or brc(1M)
+  (let* (word
+	 (ret "")
+	 (table (syntax-table))
+	 (orig  (copy-sequence table)))
+    (modify-syntax-entry ?\( "w" table)
+    (modify-syntax-entry ?\) "w" table)
+    (modify-syntax-entry ?. "w" table)  ;; snmpd.conf(5) 
+    (modify-syntax-entry ?- "w" table)  ;; invoke-rc.d(8)
+    (set-syntax-table table)
       (setq word (current-word))
+    (set-syntax-table orig)
       (if (string-match "[._]+$" word)
 	  (setq word (substring word 0 (match-beginning 0))))
-      ;; If looking at something like ioctl(2) or brc(1M), include the
-      ;; section number in the returned value.  Remove text properties.
-      (forward-word 1)
+    ;; Delete leading "-.()".
+    (if (string-match "[a-zA-Z].*$" word)
+	(setq word (match-string 0 word)))
       ;; Use `format' here to clear any text props from `word'.
-      (format "%s%s"
-	      word
-	      (if (looking-at
-		   (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)"))
-		  (format "(%s)" (Man-match-substring 1))
-		"")))))
+    (cond
+     ((string-match (format "[^ \t\r\n]+(%s)" Man-section-regexp) word)
+      (setq ret (format "%s" (match-string 0 word))))
+     ((string-match "[^ \t\r\n()]+" word)
+      (setq word (match-string 0 word))
+      (if (> (length word) 1)
+	  (setq ret (format "%s" word)))))
+    ret))
 
 \f
 ;; ======================================================================

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

* Re: [21.3] [patch] M-x man does not pick word 'snmpd.conf(5)'
  2004-11-21 16:47 [21.3] [patch] M-x man does not pick word 'snmpd.conf(5)' Jari Aalto
@ 2004-11-21 20:06 ` Andreas Schwab
  2004-11-25 16:27   ` Jari Aalto
       [not found]   ` <mailman.1459.1101400640.27204.bug-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Andreas Schwab @ 2004-11-21 20:06 UTC (permalink / raw)
  Cc: bug-gnu-emacs

Jari Aalto <jari.aalto@cante.net> writes:

> --- man.el.orig	2004-11-21 18:05:53.000000000 +0200
> +++ man.el	2004-11-21 18:45:26.000000000 +0200
> @@ -502,23 +502,35 @@
>  (defsubst Man-default-man-entry ()
>    "Make a guess at a default manual entry.
>  This guess is based on the text surrounding the cursor."
> -  (let (word)
> -    (save-excursion
>        ;; Default man entry title is any word the cursor is on, or if
>        ;; cursor not on a word, then nearest preceding word.
> +  ;; Use local syntax table to find correct word in cases like:
> +  ;;    ioctl(2) or brc(1M)
> +  (let* (word
> +	 (ret "")
> +	 (table (syntax-table))
> +	 (orig  (copy-sequence table)))
> +    (modify-syntax-entry ?\( "w" table)
> +    (modify-syntax-entry ?\) "w" table)
> +    (modify-syntax-entry ?. "w" table)  ;; snmpd.conf(5) 
> +    (modify-syntax-entry ?- "w" table)  ;; invoke-rc.d(8)
> +    (set-syntax-table table)
>        (setq word (current-word))
> +    (set-syntax-table orig)

That should use with-syntax-table to not lose the old syntax table in case
of errors or quit (even if it is rather unlikely to occur).

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: [21.3] [patch] M-x man does not pick word 'snmpd.conf(5)'
  2004-11-21 20:06 ` Andreas Schwab
@ 2004-11-25 16:27   ` Jari Aalto
       [not found]   ` <mailman.1459.1101400640.27204.bug-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Jari Aalto @ 2004-11-25 16:27 UTC (permalink / raw)


Andreas Schwab <schwab@suse.de> writes:
| Jari Aalto <jari.aalto@cante.net> writes:
| 
| > --- man.el.orig	2004-11-21 18:05:53.000000000 +0200
| > +++ man.el	2004-11-21 18:45:26.000000000 +0200
| > @@ -502,23 +502,35 @@
| >  (defsubst Man-default-man-entry ()
| >    "Make a guess at a default manual entry.
| >  This guess is based on the text surrounding the cursor."
| > -  (let (word)
| > -    (save-excursion
| >        ;; Default man entry title is any word the cursor is on, or if
| >        ;; cursor not on a word, then nearest preceding word.
| > +  ;; Use local syntax table to find correct word in cases like:
| > +  ;;    ioctl(2) or brc(1M)
| > +  (let* (word
| > +	 (ret "")
| > +	 (table (syntax-table))
| > +	 (orig  (copy-sequence table)))
| > +    (modify-syntax-entry ?\( "w" table)
| > +    (modify-syntax-entry ?\) "w" table)
| > +    (modify-syntax-entry ?. "w" table)  ;; snmpd.conf(5)=20
| > +    (modify-syntax-entry ?- "w" table)  ;; invoke-rc.d(8)
| > +    (set-syntax-table table)
| >        (setq word (current-word))
| > +    (set-syntax-table orig)
| 
| That should use with-syntax-table to not lose the old syntax table in cas=
| e
| of errors or quit (even if it is rather unlikely to occur).

Here.

Jari

2004-11-21  Jari Aalto  <jari aalto A T cante net>

	* man.el (Man-default-man-entry): Use local syntax
	table to get correct full word in cases like 'snmpd.conf(5)'
        and invoke-rc.d(8)

--- man.el.orig	2004-11-21 18:05:53.000000000 +0200
+++ man.el	2004-11-25 18:16:41.000000000 +0200
@@ -502,23 +502,33 @@
 (defsubst Man-default-man-entry ()
   "Make a guess at a default manual entry.
 This guess is based on the text surrounding the cursor."
-  (let (word)
-    (save-excursion
       ;; Default man entry title is any word the cursor is on, or if
       ;; cursor not on a word, then nearest preceding word.
+  ;; Use local syntax table to find correct word in cases like:
+  ;;    ioctl(2) or brc(1M)
+  (let (word
+	(ret "")
+	(table (syntax-table)))
+    (with-syntax-table table
+      (modify-syntax-entry ?\( "w" table)
+      (modify-syntax-entry ?\) "w" table)
+      (modify-syntax-entry ?.  "w" table)  ;; snmpd.conf(5) 
+      (modify-syntax-entry ?-  "w" table)  ;; invoke-rc.d(8)
       (setq word (current-word))
       (if (string-match "[._]+$" word)
 	  (setq word (substring word 0 (match-beginning 0))))
-      ;; If looking at something like ioctl(2) or brc(1M), include the
-      ;; section number in the returned value.  Remove text properties.
-      (forward-word 1)
+      ;; Delete leading "-.()".
+      (if (string-match "[a-zA-Z].*$" word)
+	  (setq word (match-string 0 word)))
       ;; Use `format' here to clear any text props from `word'.
-      (format "%s%s"
-	      word
-	      (if (looking-at
-		   (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)"))
-		  (format "(%s)" (Man-match-substring 1))
-		"")))))
+      (cond
+       ((string-match (format "[^ \t\r\n]+(%s)" Man-section-regexp) word)
+	(setq ret (format "%s" (match-string 0 word))))
+       ((string-match "[^ \t\r\n()]+" word)
+	(setq word (match-string 0 word))
+	(if (> (length word) 1)
+	    (setq ret (format "%s" word)))))
+      ret)))
 
 \f
 ;; ======================================================================

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

* Re: [21.3] [patch] M-x man does not pick word 'snmpd.conf(5)'
       [not found]   ` <mailman.1459.1101400640.27204.bug-gnu-emacs@gnu.org>
@ 2004-11-25 19:27     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2004-11-25 19:27 UTC (permalink / raw)


> 2004-11-21  Jari Aalto  <jari aalto A T cante net>

> 	* man.el (Man-default-man-entry): Use local syntax
> 	table to get correct full word in cases like 'snmpd.conf(5)'
>         and invoke-rc.d(8)

I guess it would have been better to start from the code in CVS rather than
the code in Emacs-21.3.  Especially since this problem had already been
fixed in Emacs-CVS.


        Stefan

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

end of thread, other threads:[~2004-11-25 19:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-21 16:47 [21.3] [patch] M-x man does not pick word 'snmpd.conf(5)' Jari Aalto
2004-11-21 20:06 ` Andreas Schwab
2004-11-25 16:27   ` Jari Aalto
     [not found]   ` <mailman.1459.1101400640.27204.bug-gnu-emacs@gnu.org>
2004-11-25 19:27     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).