From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Newsgroups: gmane.emacs.bugs Subject: bug#39842: [PATCH] Use help-fns-short-filename in other describe- commands Date: Sat, 29 Feb 2020 22:47:36 +0100 Message-ID: <87r1yd83rb.fsf@gmail.com> References: <20200229190008.338460-1-stepnem@gmail.com> <87zhd187vq.fsf@gmail.com> <87v9np86vh.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="60777"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Notmuch/0.29.3 (https://notmuchmail.org) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: 39842@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 29 22:48:14 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j89y0-000FeI-W1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 29 Feb 2020 22:48:13 +0100 Original-Received: from localhost ([::1]:36120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j89xz-0004du-Ld for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 29 Feb 2020 16:48:11 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57674) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j89xs-0004dc-5m for bug-gnu-emacs@gnu.org; Sat, 29 Feb 2020 16:48:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j89xq-000122-CR for bug-gnu-emacs@gnu.org; Sat, 29 Feb 2020 16:48:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57754) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j89xq-00011u-6q for bug-gnu-emacs@gnu.org; Sat, 29 Feb 2020 16:48:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j89xq-0000Bx-4s for bug-gnu-emacs@gnu.org; Sat, 29 Feb 2020 16:48:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Feb 2020 21:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39842 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 39842-submit@debbugs.gnu.org id=B39842.1583012852702 (code B ref 39842); Sat, 29 Feb 2020 21:48:02 +0000 Original-Received: (at 39842) by debbugs.gnu.org; 29 Feb 2020 21:47:32 +0000 Original-Received: from localhost ([127.0.0.1]:35494 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j89xM-0000BF-42 for submit@debbugs.gnu.org; Sat, 29 Feb 2020 16:47:32 -0500 Original-Received: from mail-wr1-f66.google.com ([209.85.221.66]:39122) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j89xK-0000B2-Eu for 39842@debbugs.gnu.org; Sat, 29 Feb 2020 16:47:31 -0500 Original-Received: by mail-wr1-f66.google.com with SMTP id y17so7739335wrn.6 for <39842@debbugs.gnu.org>; Sat, 29 Feb 2020 13:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version; bh=OegRcyGj7ym153SIEmLvRuFjvs4gHQdRmcDRD2qYdXU=; b=aC0mY1qs2udXoGxHkZ4SBr4pg19w1XfKbj2kGosyQ98dIoRObPHAPMSrqSvZ/somFt C2+fMdnbhQO14HdiKzE2JBU0fp6+1uppSF54J1+5+FVp40/MMWtJPZbvMA4uxT6CpW8M yESFC0Xm7OKvXrL2joIi+hysll5KEI/qMzqGrIY+TIEfmtRwnaYFSnilDQ4B60mOKNdr xuWW0Z14PxhI+tLpXldVydU8KwmP1P544DgFEMr73BnDF2VwuWP4XxTRvcphZ2XhEzC3 g8HubfD7MFTIbgq3rrOwJ2boTSPNOfh+QB1wAtUhkLFs9KBIGtcVxUM+N08MJeGwwWwX 9OGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version; bh=OegRcyGj7ym153SIEmLvRuFjvs4gHQdRmcDRD2qYdXU=; b=tuWZIFfrn1EBKV0ErvMeMK8UutNUPiWHZALz7sNAx25VY1ga4tijHk/PN6xLd4mwTe EXmErKnDJPM3O3VBdT+PkWkIJmKp1CL4Pxtj9CsxyYVguyL+bmoI+Adbn573UjFGG2le 6NY6nP+G+ZA/S3bt7yjt8kNdZAgFSCRBzu0LwsOf1TUjLvXFIakkb1By1/YSBx1BdD5x vUqJQBAMVL6QEt65aw09SFq+I3knGr7XRf0H33T0PyqPn8x6ifsS2hIzFMQK0WeNQ2my NUWl/hj0VXFPyY54/Nm8P1Mmqyt8RCqTYCtGo0Bprsdlulu2MZT8qOFy6cfQ5Cp72k8v vtxg== X-Gm-Message-State: APjAAAXuFTfuvsj2i0t2eH3vfzJ+0VSK2qeAzQOgXnOA3y3CF+lxGp8q 69ONEcriBu8uRsV9M7eIM7F2rUCW X-Google-Smtp-Source: APXvYqy7azcnrw+tPc4NlmtmOkRvt71etZbJVfcN9l97/Fl0lHnoWULT8jqRbVHNJDQnL5s//cAzxg== X-Received: by 2002:a05:6000:2:: with SMTP id h2mr6894048wrx.182.1583012844485; Sat, 29 Feb 2020 13:47:24 -0800 (PST) Original-Received: from localhost ([185.112.167.59]) by smtp.gmail.com with ESMTPSA id d15sm15144304wrp.37.2020.02.29.13.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Feb 2020 13:47:23 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:176697 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, 29 Feb 2020 16:07:46 -0500 Stefan Monnier wrote: > I.e. I think the better answer is that `describe-mode` should move to > `help-fns.el`. Patch updated to that effect attached. Thank you, =C5=A0t=C4=9Bp=C3=A1n --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Use-help-fns-short-filename-in-other-describe-comman.patch >From f9edbe36d6c56f7bf64ba687d525e48fd8762cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= Date: Sat, 29 Feb 2020 19:43:53 +0100 Subject: [PATCH] Use help-fns-short-filename in other describe- commands The commit 2015-01-16T22:52:15-05:00!monnier@iro.umontreal.ca 24b7f77581 (Improve handling of doc-strings and describe-function for cl-generic) added 'help-fns-short-filename', which provides file name shortening smarter than a simple 'file-name-nondirectory' call, but besides the generic/eieio functions ('cl--generic-describe', 'cl--describe-class', 'eieio-help-constructor'), it is currently only used by 'describe-function' (via 'help-fns-function-description-header'). Make the other help commands use it, too. (Other than the obvious consistency/maintenance argument, my immediate motivation for this change is the possibility to customize the file name abbreviation by advising the function.) * lisp/help.el (describe-mode): Move to help-fns.el. The command was already depending on 'find-lisp-object-file-name' defined there. * lisp/help-fns.el (describe-variable) (describe-face) (describe-keymap) (describe-mode): Use 'help-fns-short-filename'. --- lisp/help-fns.el | 116 +++++++++++++++++++++++++++++++++++++++++++++-- lisp/help.el | 108 ------------------------------------------- 2 files changed, 112 insertions(+), 112 deletions(-) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 36c2a8b186..ad496166f5 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -968,7 +968,7 @@ describe-variable " is a variable defined in `%s'.\n" (if (eq file-name 'C-source) "C source code" - (file-name-nondirectory file-name)))) + (help-fns-short-filename file-name)))) (with-current-buffer standard-output (save-excursion (re-search-backward (substitute-command-keys @@ -1350,7 +1350,7 @@ describe-face (setq file-name (find-lisp-object-file-name f 'defface)) (when file-name (princ (substitute-command-keys "Defined in `")) - (princ (file-name-nondirectory file-name)) + (princ (help-fns-short-filename file-name)) (princ (substitute-command-keys "'")) ;; Make a hyperlink to the library. (save-excursion @@ -1642,7 +1642,7 @@ describe-keymap " defined in `%s'.\n\n" (if (eq file-name 'C-source) "C source code" - (file-name-nondirectory file-name)))) + (help-fns-short-filename file-name)))) (save-excursion (re-search-backward (substitute-command-keys "`\\([^`']+\\)'") @@ -1658,7 +1658,115 @@ describe-keymap ;; Cleanup. (when used-gentemp (makunbound keymap)))) - + +;;;###autoload +(defun describe-mode (&optional buffer) + "Display documentation of current major mode and minor modes. +A brief summary of the minor modes comes first, followed by the +major mode description. This is followed by detailed +descriptions of the minor modes, each on a separate page. + +For this to work correctly for a minor mode, the mode's indicator +variable \(listed in `minor-mode-alist') must also be a function +whose documentation describes the minor mode. + +If called from Lisp with a non-nil BUFFER argument, display +documentation for the major and minor modes of that buffer." + (interactive "@") + (unless buffer (setq buffer (current-buffer))) + (help-setup-xref (list #'describe-mode buffer) + (called-interactively-p 'interactive)) + ;; For the sake of help-do-xref and help-xref-go-back, + ;; don't switch buffers before calling `help-buffer'. + (with-help-window (help-buffer) + (with-current-buffer buffer + (let (minor-modes) + ;; Older packages do not register in minor-mode-list but only in + ;; minor-mode-alist. + (dolist (x minor-mode-alist) + (setq x (car x)) + (unless (memq x minor-mode-list) + (push x minor-mode-list))) + ;; Find enabled minor mode we will want to mention. + (dolist (mode minor-mode-list) + ;; Document a minor mode if it is listed in minor-mode-alist, + ;; non-nil, and has a function definition. + (let ((fmode (or (get mode :minor-mode-function) mode))) + (and (boundp mode) (symbol-value mode) + (fboundp fmode) + (let ((pretty-minor-mode + (if (string-match "\\(\\(-minor\\)?-mode\\)?\\'" + (symbol-name fmode)) + (capitalize + (substring (symbol-name fmode) + 0 (match-beginning 0))) + fmode))) + (push (list fmode pretty-minor-mode + (format-mode-line (assq mode minor-mode-alist))) + minor-modes))))) + ;; Narrowing is not a minor mode, but its indicator is part of + ;; mode-line-modes. + (when (buffer-narrowed-p) + (push '(narrow-to-region "Narrow" " Narrow") minor-modes)) + (setq minor-modes + (sort minor-modes + (lambda (a b) (string-lessp (cadr a) (cadr b))))) + (when minor-modes + (princ "Enabled minor modes:\n") + (make-local-variable 'help-button-cache) + (with-current-buffer standard-output + (dolist (mode minor-modes) + (let ((mode-function (nth 0 mode)) + (pretty-minor-mode (nth 1 mode)) + (indicator (nth 2 mode))) + (save-excursion + (goto-char (point-max)) + (princ "\n\f\n") + (push (point-marker) help-button-cache) + ;; Document the minor modes fully. + (insert-text-button + pretty-minor-mode 'type 'help-function + 'help-args (list mode-function) + 'button '(t)) + (princ (format " minor mode (%s):\n" + (if (zerop (length indicator)) + "no indicator" + (format "indicator%s" + indicator)))) + (princ (help-split-fundoc (documentation mode-function) + nil 'doc))) + (insert-button pretty-minor-mode + 'action (car help-button-cache) + 'follow-link t + 'help-echo "mouse-2, RET: show full information") + (newline))) + (forward-line -1) + (fill-paragraph nil) + (forward-line 1)) + + (princ "\n(Information about these minor modes follows the major mode info.)\n\n")) + ;; Document the major mode. + (let ((mode mode-name)) + (with-current-buffer standard-output + (let ((start (point))) + (insert (format-mode-line mode nil nil buffer)) + (add-text-properties start (point) '(face bold))))) + (princ " mode") + (let* ((mode major-mode) + (file-name (find-lisp-object-file-name mode nil))) + (when file-name + (princ (format-message " defined in `%s'" + (help-fns-short-filename file-name))) + ;; Make a hyperlink to the library. + (with-current-buffer standard-output + (save-excursion + (re-search-backward (substitute-command-keys "`\\([^`']+\\)'") + nil t) + (help-xref-button 1 'help-function-def mode file-name))))) + (princ ":\n") + (princ (help-split-fundoc (documentation major-mode) nil 'doc))))) + ;; For the sake of IELM and maybe others + nil) ;;; Replacements for old lib-src/ programs. Don't seem especially useful. diff --git a/lisp/help.el b/lisp/help.el index 45cbaad4e8..e40ed479e0 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -879,114 +879,6 @@ describe-key (princ ", which is ") (describe-function-1 defn))))))) -(defun describe-mode (&optional buffer) - "Display documentation of current major mode and minor modes. -A brief summary of the minor modes comes first, followed by the -major mode description. This is followed by detailed -descriptions of the minor modes, each on a separate page. - -For this to work correctly for a minor mode, the mode's indicator -variable \(listed in `minor-mode-alist') must also be a function -whose documentation describes the minor mode. - -If called from Lisp with a non-nil BUFFER argument, display -documentation for the major and minor modes of that buffer." - (interactive "@") - (unless buffer (setq buffer (current-buffer))) - (help-setup-xref (list #'describe-mode buffer) - (called-interactively-p 'interactive)) - ;; For the sake of help-do-xref and help-xref-go-back, - ;; don't switch buffers before calling `help-buffer'. - (with-help-window (help-buffer) - (with-current-buffer buffer - (let (minor-modes) - ;; Older packages do not register in minor-mode-list but only in - ;; minor-mode-alist. - (dolist (x minor-mode-alist) - (setq x (car x)) - (unless (memq x minor-mode-list) - (push x minor-mode-list))) - ;; Find enabled minor mode we will want to mention. - (dolist (mode minor-mode-list) - ;; Document a minor mode if it is listed in minor-mode-alist, - ;; non-nil, and has a function definition. - (let ((fmode (or (get mode :minor-mode-function) mode))) - (and (boundp mode) (symbol-value mode) - (fboundp fmode) - (let ((pretty-minor-mode - (if (string-match "\\(\\(-minor\\)?-mode\\)?\\'" - (symbol-name fmode)) - (capitalize - (substring (symbol-name fmode) - 0 (match-beginning 0))) - fmode))) - (push (list fmode pretty-minor-mode - (format-mode-line (assq mode minor-mode-alist))) - minor-modes))))) - ;; Narrowing is not a minor mode, but its indicator is part of - ;; mode-line-modes. - (when (buffer-narrowed-p) - (push '(narrow-to-region "Narrow" " Narrow") minor-modes)) - (setq minor-modes - (sort minor-modes - (lambda (a b) (string-lessp (cadr a) (cadr b))))) - (when minor-modes - (princ "Enabled minor modes:\n") - (make-local-variable 'help-button-cache) - (with-current-buffer standard-output - (dolist (mode minor-modes) - (let ((mode-function (nth 0 mode)) - (pretty-minor-mode (nth 1 mode)) - (indicator (nth 2 mode))) - (save-excursion - (goto-char (point-max)) - (princ "\n\f\n") - (push (point-marker) help-button-cache) - ;; Document the minor modes fully. - (insert-text-button - pretty-minor-mode 'type 'help-function - 'help-args (list mode-function) - 'button '(t)) - (princ (format " minor mode (%s):\n" - (if (zerop (length indicator)) - "no indicator" - (format "indicator%s" - indicator)))) - (princ (help-split-fundoc (documentation mode-function) - nil 'doc))) - (insert-button pretty-minor-mode - 'action (car help-button-cache) - 'follow-link t - 'help-echo "mouse-2, RET: show full information") - (newline))) - (forward-line -1) - (fill-paragraph nil) - (forward-line 1)) - - (princ "\n(Information about these minor modes follows the major mode info.)\n\n")) - ;; Document the major mode. - (let ((mode mode-name)) - (with-current-buffer standard-output - (let ((start (point))) - (insert (format-mode-line mode nil nil buffer)) - (add-text-properties start (point) '(face bold))))) - (princ " mode") - (let* ((mode major-mode) - (file-name (find-lisp-object-file-name mode nil))) - (when file-name - (princ (format-message " defined in `%s'" - (file-name-nondirectory file-name))) - ;; Make a hyperlink to the library. - (with-current-buffer standard-output - (save-excursion - (re-search-backward (substitute-command-keys "`\\([^`']+\\)'") - nil t) - (help-xref-button 1 'help-function-def mode file-name))))) - (princ ":\n") - (princ (help-split-fundoc (documentation major-mode) nil 'doc))))) - ;; For the sake of IELM and maybe others - nil) - (defun search-forward-help-for-help () "Search forward \"help window\"." (interactive) -- 2.25.1 --=-=-=--