From: martin rudalics <rudalics@gmx.at>
To: jidanni@jidanni.org
Cc: bug-gnu-emacs@gnu.org
Subject: Re: M-x man could better guess neighboring word
Date: Sun, 16 Dec 2007 11:11:17 +0100 [thread overview]
Message-ID: <4764F9C5.6070706@gmx.at> (raw)
In-Reply-To: <87bq8slp16.fsf@jidanni.org>
[-- Attachment #1: Type: text/plain, Size: 345 bytes --]
> Principles: always offer at least two default choices, one
> forwards/beneath, one backwards/beneath the cursor. The topmost of
> which should be the closest to the cursor. Skip past punctuation at
> the ends of sentences too...
Does the attached patch obey these principles? I'm not quite sure
which characters shall consitute punctuation.
[-- Attachment #2: man.patch --]
[-- Type: text/plain, Size: 3106 bytes --]
*** man.el.~1.175.~ Sat Dec 8 10:07:02 2007
--- man.el Sun Dec 16 11:06:08 2007
***************
*** 647,672 ****
(defsubst Man-default-man-entry (&optional pos)
"Make a guess at a default manual entry based on the text at POS.
If POS is nil, the current point is used."
! (let (word)
(save-excursion
(if pos (goto-char pos))
;; Default man entry title is any word the cursor is on, or if
! ;; cursor not on a word, then nearest preceding word.
! (skip-chars-backward "-a-zA-Z0-9._+:")
! (let ((start (point)))
! (skip-chars-forward "-a-zA-Z0-9._+:")
! ;; If there is a continuation at the end of line, check the
! ;; following line too, eg:
! ;; see this-
! ;; command-here(1)
! (setq word (buffer-substring-no-properties start (point)))
! (if (looking-at "[ \t\r\n]+\\([-a-zA-Z0-9._+:]+\\)([0-9])")
! (setq word (concat word (match-string 1)))))
! (if (string-match "[._]+$" word)
! (setq word (substring word 0 (match-beginning 0))))
;; If looking at something like *strcat(... , remove the '*'
! (if (string-match "^*" word)
! (setq word (substring word 1)))
;; If looking at something like ioctl(2) or brc(1M), include the
;; section number in the returned value. Remove text properties.
(concat word
--- 647,685 ----
(defsubst Man-default-man-entry (&optional pos)
"Make a guess at a default manual entry based on the text at POS.
If POS is nil, the current point is used."
! (let (word start original-pos distance)
(save-excursion
(if pos (goto-char pos))
;; Default man entry title is any word the cursor is on, or if
! ;; cursor not on a word, nearest preceding or next word on this
! ;; line.
! (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:")))
! (setq start (point))
! (setq original-pos (point))
! (setq distance (abs (skip-chars-backward " \t")))
! (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:")))
! (progn
! (setq start (point))
! (goto-char original-pos)
! (if (and (< (skip-chars-forward " \t") distance)
! (looking-at "[-a-zA-Z0-9._+:]"))
! (setq start (point))
! (goto-char start)))
! (skip-chars-forward " \t")
! (setq start (point))))
! (skip-chars-forward "-a-zA-Z0-9._+:")
! (setq word (buffer-substring-no-properties start (point)))
! ;; If there is a continuation at the end of line, check the
! ;; following line too, eg:
! ;; see this-
! ;; command-here(1)
! (when (looking-at "[ \t\r\n]+\\([-a-zA-Z0-9._+:]+\\)([0-9])")
! (setq word (concat word (match-string-no-properties 1))))
! (when (string-match "[._]+$" word)
! (setq word (substring word 0 (match-beginning 0))))
;; If looking at something like *strcat(... , remove the '*'
! (when (string-match "^*" word)
! (setq word (substring word 1)))
;; If looking at something like ioctl(2) or brc(1M), include the
;; section number in the returned value. Remove text properties.
(concat word
next prev parent reply other threads:[~2007-12-16 10:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-14 8:07 M-x man could better guess neighboring word jidanni
2007-12-14 9:40 ` martin rudalics
2007-12-15 1:33 ` jidanni
2007-12-16 10:11 ` martin rudalics [this message]
2007-12-17 13:38 ` jidanni
2007-12-17 22:19 ` martin rudalics
2007-12-18 1:53 ` jidanni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4764F9C5.6070706@gmx.at \
--to=rudalics@gmx.at \
--cc=bug-gnu-emacs@gnu.org \
--cc=jidanni@jidanni.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.