From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ibeas@gmx.com (=?UTF-8?Q?=C3=81lvar?= Ibeas) Newsgroups: gmane.emacs.bugs Subject: bug#19359: Buttons in man pages Date: Wed, 17 Dec 2014 23:15:56 +0100 Message-ID: <87bnn1ylb7.fsf@gmx.com> References: <87a92tf066.fsf@gmx.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1418854657 7222 80.91.229.3 (17 Dec 2014 22:17:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Dec 2014 22:17:37 +0000 (UTC) To: 19359@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 17 23:17:29 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y1MuI-0001nj-SF for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 23:17:23 +0100 Original-Received: from localhost ([::1]:51755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1MuI-0006l9-4F for geb-bug-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 17:17:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1Mu6-0006kx-DS for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 17:17:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1Mty-0006kA-RY for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 17:17:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:39963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1Mty-0006k2-NT for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 17:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y1Mtx-0007s0-Ky for bug-gnu-emacs@gnu.org; Wed, 17 Dec 2014 17:17:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87a92tf066.fsf@gmx.com> Resent-From: ibeas@gmx.com (=?UTF-8?Q?=C3=81lvar?= Ibeas) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 17 Dec 2014 22:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19359 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 19359-submit@debbugs.gnu.org id=B19359.141885456430182 (code B ref 19359); Wed, 17 Dec 2014 22:17:01 +0000 Original-Received: (at 19359) by debbugs.gnu.org; 17 Dec 2014 22:16:04 +0000 Original-Received: from localhost ([127.0.0.1]:49329 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1Mt1-0007qf-4c for submit@debbugs.gnu.org; Wed, 17 Dec 2014 17:16:04 -0500 Original-Received: from mout.gmx.net ([212.227.17.22]:53982) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1Msy-0007qD-BN for 19359@debbugs.gnu.org; Wed, 17 Dec 2014 17:16:01 -0500 Original-Received: from yermo ([84.127.142.133]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0LpbfG-1XOTtJ1PHS-00fSjw; Wed, 17 Dec 2014 23:15:59 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Provags-ID: V03:K0:zs0JKSXzDUeOWE+uRhyeEoK4l1tRbM/KEh77++5C7SJ6lKLYwXq ggH45nzOeyaOyxCf3yPT/7AEA0L+kWo7XD2QbojcfiikMci2sCSHo2mTkb8sU/ZnIqiKXWt ZdC54DZN4NRq9HigbHJ3QBjLFOUDpm6szLSR3VE5lawo5v0UwcwJ5ANKUzsyC9KIHAix/40 w3NRMqD1JQFXROzHvODWA== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:97473 Archived-At: --=-=-= Content-Type: text/plain Here is another suggestion that could serve as an approach to avoid cross-references being interpreted as word-wrapped links, when the previous line doesn't end with a hyphen. This one allows references to span more than two lines. The variable `Man-name-regexp' is changed to include line breaks. Hopefully, this doesn't mess up (many) other things. As an advantage, with this approach, a cross-reference outside the `SEE ALSO' section that is split across two (or more) lines can be followed by typing RET not only with point on the first of them. --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename=patch_a3 Content-Transfer-Encoding: quoted-printable Content-Description: patch_a3 diff --git a/lisp/man.el b/lisp/man.el index a61524b..51e5b1b 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -275,7 +275,22 @@ Used in `bookmark-set' to get the default bookmark nam= e." :type 'hook :group 'man) =20 -(defvar Man-name-regexp "[-a-zA-Z0-9_=C2=AD+][-a-zA-Z0-9_.:=C2=AD+]*" +(defvar Man-name-leading-character "[-a-zA-Z0-9_+]" + "Regular expression describing the first character of the name of a manp= age.") + +(defvar Man-name-character "[-a-zA-Z0-9_.:+]" + "Regular expression describing a generic character in the name of a manp= age.") + +(defvar Man-hyphenation-added-character "[\u2010\u00AD]" + "Regular expression describing a character added to break a name.") + +(defvar Man-hyphenation-character + (concat "\\(?:-\\|" Man-hyphenation-added-character "\\)") + "Regular expression describing a character used for hyphenation.") + +(defvar Man-name-regexp + (concat "\\(\\_<" Man-name-leading-character "\\(" Man-name-character "*= ?" + Man-hyphenation-character "\n[ \t]*\\)*" Man-name-character "*\\_>\\)") "Regular expression describing the name of a manpage (without section).") =20 (defvar Man-section-regexp "[0-9][a-zA-Z0-9+]*\\|[LNln]" @@ -304,9 +319,7 @@ This regexp should not start with a `^' character.") This regular expression should start with a `^' character.") =20 (defvar Man-reference-regexp - (concat "\\(" Man-name-regexp - "\\(\n[ \t]+" Man-name-regexp "\\)*\\)[ \t]*(\\(" - Man-section-regexp "\\))") + (concat Man-name-regexp "[ \t]*(\\(" Man-section-regexp "\\))") "Regular expression describing a reference to another manpage.") =20 (defvar Man-apropos-regexp @@ -707,7 +720,33 @@ a \"/\" as a local filename. The function returns eit= her `man-db' 'man)))) Man-support-local-filenames)) =20 - + +(defun Man-skip-name-backward () + "Move point backward until the beginning of what seems to be a +name. Return the name length." + (let (travel) + (setq travel (skip-chars-backward "-a-zA-Z0-9_.:+")) + (while (looking-back (concat Man-hyphenation-character "\n[ \t]*")) + (end-of-line 0) + (backward-char) + (setq travel (+ travel + (skip-chars-backward "-a-zA-Z0-9_.:+")))) + travel)) + +(defun Man-skip-name-forward () + "Move point forward until the end of what seems to be a name. +Return the name length." + (let (travel) + (setq travel (skip-chars-forward "-a-zA-Z0-9_.:+")) + (while (or (and (looking-back "-") + (looking-at "$")) + (looking-at (concat Man-hyphenation-character "$"))) + (beginning-of-line 2) + (skip-chars-forward "[ \t]*") + (setq travel (+ travel + (skip-chars-forward "-a-zA-Z0-9_.:+")))) + travel)) + ;; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ;; default man entry: get word near point =20 @@ -729,7 +768,7 @@ POS defaults to `point'." ;; We skipped a valid section number backwards, look at ;; preceding text. (or (and (skip-chars-backward ",; \t") - (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:")))) + (not (zerop (Man-skip-name-backward)))) ;; Not a valid entry, move POS after closing paren. (not (setq pos (match-end 0))))) ;; We have a candidate, make `start' record its starting @@ -737,7 +776,7 @@ POS defaults to `point'." (setq start (point)) ;; Otherwise look at char before POS. (goto-char pos) - (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:"))) + (if (not (zerop (Man-skip-name-backward))) ;; Our candidate is just before or around POS. (setq start (point)) ;; Otherwise record the current column and look backwards. @@ -750,7 +789,7 @@ POS defaults to `point'." ;; Skip section number backwards. (goto-char (match-beginning 0)) (skip-chars-backward " \t")) - (if (not (zerop (skip-chars-backward "-a-zA-Z0-9._+:"))) + (if (not (zerop (Man-skip-name-backward))) (progn ;; We have a candidate before POS ... (setq start (point)) @@ -768,17 +807,12 @@ POS defaults to `point'." (setq start (point))))) ;; We have found a suitable starting point, try to skip at least ;; one character. - (skip-chars-forward "-a-zA-Z0-9._+:") + (Man-skip-name-forward) (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) - ;; Note: This code gets executed iff our entry is after POS. - (when (looking-at "[ \t\r\n]+\\([-a-zA-Z0-9._+:]+\\)([0-9])") - (setq word (concat word (match-string-no-properties 1))) - ;; Make sure the section number gets included by the code below. - (goto-char (match-end 1))) + (setq word (replace-regexp-in-string + (concat "\\([ \t\n]\\|" + Man-hyphenation-added-character "\\)") + "" word)) (when (string-match "[-._]+$" word) (setq word (substring word 0 (match-beginning 0)))) ;; The following was commented out since the preceding code @@ -786,14 +820,14 @@ POS defaults to `point'." ;;; ;; If looking at something like *strcat(... , remove the '*' ;;; (when (string-match "^*" word) ;;; (setq word (substring word 1))) - (concat - word - (and (not (string-equal word "")) - ;; If looking at something like ioctl(2) or brc(1M), - ;; include the section number in the returned value. - (looking-at - (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)")) - (format "(%s)" (match-string-no-properties 1))))))) + (concat + word + (and (not (string-equal word "")) + ;; If looking at something like ioctl(2) or brc(1M), + ;; include the section number in the returned value. + (looking-at + (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)")) + (format "(%s)" (match-string-no-properties 1))))))) =20 ;; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -1535,7 +1569,7 @@ The following key bindings are currently in effect in= the buffer: (end (progn (Man-next-section 1) (point))) - hyphenated + ;; hyphenated (runningpoint -1)) (save-restriction (narrow-to-region start end) @@ -1543,18 +1577,22 @@ The following key bindings are currently in effect = in the buffer: (back-to-indentation) (while (and (not (eobp)) (/=3D (point) runningpoint)) (setq runningpoint (point)) - (if (re-search-forward Man-hyphenated-reference-regexp end t) - (let* ((word (match-string 0)) - (len (1- (length word)))) - (if hyphenated - (setq word (concat hyphenated word) - hyphenated nil - ;; Update len, in case a reference spans - ;; more than two lines (paranoia). - len (1- (length word)))) - (if (memq (aref word len) '(?- ?=C2=AD)) - (setq hyphenated (substring word 0 len))) - (and (string-match Man-reference-regexp word) + (if (re-search-forward Man-reference-regexp end t) + (let* ((word (match-string 0))) + ;; (len (1- (length word))) + ;; (if hyphenated + ;; (setq word (concat hyphenated word) + ;; hyphenated nil + ;; ;; Update len, in case a reference spans + ;; ;; more than two lines (paranoia). + ;; len (1- (length word)))) + ;; (if (memq (aref word len) '(?- ?=C2=AD)) + ;; (setq hyphenated (substring word 0 len))) + (setq word (replace-regexp-in-string + (concat "\\([ \t\n]\\|" + Man-hyphenation-added-character "\\)") + "" word)) + (and ;(string-match Man-reference-regexp word) (not (member word Man--refpages)) (push word Man--refpages)))) (skip-chars-forward " \t\n,")))))) @@ -1720,25 +1758,25 @@ Actually the section moved to is described by `Man-= see-also-regexp'." (error "%s" (concat "No " Man-see-also-regexp " section found in the current manpage")))) =20 -(defun Man-possibly-hyphenated-word () - "Return a possibly hyphenated word at point. -If the word starts at the first non-whitespace column, and the -previous line ends with a hyphen, return the last word on the previous -line instead. Thus, if a reference to \"tcgetpgrp(3V)\" is hyphenated -as \"tcgetp-grp(3V)\", and point is at \"grp(3V)\", we return -\"tcgetp-\" instead of \"grp\"." - (save-excursion - (skip-syntax-backward "w()") - (skip-chars-forward " \t") - (let ((beg (point)) - (word (current-word))) - (when (eq beg (save-excursion - (back-to-indentation) - (point))) - (end-of-line 0) - (if (eq (char-before) ?-) - (setq word (current-word)))) - word))) +;; (defun Man-possibly-hyphenated-word () +;; "Return a possibly hyphenated word at point. +;; If the word starts at the first non-whitespace column, and the +;; previous line ends with a hyphen, return the last word on the previous +;; line instead. Thus, if a reference to \"tcgetpgrp(3V)\" is hyphenated +;; as \"tcgetp-grp(3V)\", and point is at \"grp(3V)\", we return +;; \"tcgetp-\" instead of \"grp\"." +;; (save-excursion +;; (skip-syntax-backward "w()") +;; (skip-chars-forward " \t") +;; (let ((beg (point)) +;; (word (current-word))) +;; (when (eq beg (save-excursion +;; (back-to-indentation) +;; (point))) +;; (end-of-line 0) +;; (if (eq (char-before) ?-) +;; (setq word (current-word)))) +;; word))) =20 (defvar Man--last-refpage nil) =20 @@ -1752,14 +1790,14 @@ Specify which REFERENCE to use; default is based on= word at point." (let* ((default (or (car (all-completions (let ((word - (or (Man-possibly-hyphenated-word) - ""))) + (or (Man-default-man-entry) + ""))) ;; strip a trailing '-': - (if (string-match "-$" word) - (substring word 0 - (match-beginning 0)) - word)) - Man--refpages)) + ;; (if (string-match "-$" word) + ;; (substring word 0 + ;; (match-beginning 0)) + ;; word)) + Man--refpages))) (if (member Man--last-refpage Man--refpages) Man--last-refpage (car Man--refpages)))) --=-=-=--