aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorŠtěpán Němec2020-02-29 19:43:53 +0100
committerStefan Monnier2020-03-03 10:52:27 -0500
commit0f94f698aa7ade7bad73ccae95dee69175460504 (patch)
tree5f2200c899398d43e1f0ce0a000069fc0bc5719a
parent8518b14a76ba7531a71df97994fe8a197a429d4a (diff)
downloademacs-0f94f698aa7ade7bad73ccae95dee69175460504.tar.gz
emacs-0f94f698aa7ade7bad73ccae95dee69175460504.zip
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'.
-rw-r--r--lisp/help-fns.el116
-rw-r--r--lisp/help.el108
2 files changed, 112 insertions, 112 deletions
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 36c2a8b186d..ad496166f50 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -968,7 +968,7 @@ it is displayed along with the global value."
968 " is a variable defined in `%s'.\n" 968 " is a variable defined in `%s'.\n"
969 (if (eq file-name 'C-source) 969 (if (eq file-name 'C-source)
970 "C source code" 970 "C source code"
971 (file-name-nondirectory file-name)))) 971 (help-fns-short-filename file-name))))
972 (with-current-buffer standard-output 972 (with-current-buffer standard-output
973 (save-excursion 973 (save-excursion
974 (re-search-backward (substitute-command-keys 974 (re-search-backward (substitute-command-keys
@@ -1350,7 +1350,7 @@ If FRAME is omitted or nil, use the selected frame."
1350 (setq file-name (find-lisp-object-file-name f 'defface)) 1350 (setq file-name (find-lisp-object-file-name f 'defface))
1351 (when file-name 1351 (when file-name
1352 (princ (substitute-command-keys "Defined in `")) 1352 (princ (substitute-command-keys "Defined in `"))
1353 (princ (file-name-nondirectory file-name)) 1353 (princ (help-fns-short-filename file-name))
1354 (princ (substitute-command-keys "'")) 1354 (princ (substitute-command-keys "'"))
1355 ;; Make a hyperlink to the library. 1355 ;; Make a hyperlink to the library.
1356 (save-excursion 1356 (save-excursion
@@ -1642,7 +1642,7 @@ keymap value."
1642 " defined in `%s'.\n\n" 1642 " defined in `%s'.\n\n"
1643 (if (eq file-name 'C-source) 1643 (if (eq file-name 'C-source)
1644 "C source code" 1644 "C source code"
1645 (file-name-nondirectory file-name)))) 1645 (help-fns-short-filename file-name))))
1646 (save-excursion 1646 (save-excursion
1647 (re-search-backward (substitute-command-keys 1647 (re-search-backward (substitute-command-keys
1648 "`\\([^`']+\\)'") 1648 "`\\([^`']+\\)'")
@@ -1658,7 +1658,115 @@ keymap value."
1658 ;; Cleanup. 1658 ;; Cleanup.
1659 (when used-gentemp 1659 (when used-gentemp
1660 (makunbound keymap)))) 1660 (makunbound keymap))))
1661 1661
1662;;;###autoload
1663(defun describe-mode (&optional buffer)
1664 "Display documentation of current major mode and minor modes.
1665A brief summary of the minor modes comes first, followed by the
1666major mode description. This is followed by detailed
1667descriptions of the minor modes, each on a separate page.
1668
1669For this to work correctly for a minor mode, the mode's indicator
1670variable \(listed in `minor-mode-alist') must also be a function
1671whose documentation describes the minor mode.
1672
1673If called from Lisp with a non-nil BUFFER argument, display
1674documentation for the major and minor modes of that buffer."
1675 (interactive "@")
1676 (unless buffer (setq buffer (current-buffer)))
1677 (help-setup-xref (list #'describe-mode buffer)
1678 (called-interactively-p 'interactive))
1679 ;; For the sake of help-do-xref and help-xref-go-back,
1680 ;; don't switch buffers before calling `help-buffer'.
1681 (with-help-window (help-buffer)
1682 (with-current-buffer buffer
1683 (let (minor-modes)
1684 ;; Older packages do not register in minor-mode-list but only in
1685 ;; minor-mode-alist.
1686 (dolist (x minor-mode-alist)
1687 (setq x (car x))
1688 (unless (memq x minor-mode-list)
1689 (push x minor-mode-list)))
1690 ;; Find enabled minor mode we will want to mention.
1691 (dolist (mode minor-mode-list)
1692 ;; Document a minor mode if it is listed in minor-mode-alist,
1693 ;; non-nil, and has a function definition.
1694 (let ((fmode (or (get mode :minor-mode-function) mode)))
1695 (and (boundp mode) (symbol-value mode)
1696 (fboundp fmode)
1697 (let ((pretty-minor-mode
1698 (if (string-match "\\(\\(-minor\\)?-mode\\)?\\'"
1699 (symbol-name fmode))
1700 (capitalize
1701 (substring (symbol-name fmode)
1702 0 (match-beginning 0)))
1703 fmode)))
1704 (push (list fmode pretty-minor-mode
1705 (format-mode-line (assq mode minor-mode-alist)))
1706 minor-modes)))))
1707 ;; Narrowing is not a minor mode, but its indicator is part of
1708 ;; mode-line-modes.
1709 (when (buffer-narrowed-p)
1710 (push '(narrow-to-region "Narrow" " Narrow") minor-modes))
1711 (setq minor-modes
1712 (sort minor-modes
1713 (lambda (a b) (string-lessp (cadr a) (cadr b)))))
1714 (when minor-modes
1715 (princ "Enabled minor modes:\n")
1716 (make-local-variable 'help-button-cache)
1717 (with-current-buffer standard-output
1718 (dolist (mode minor-modes)
1719 (let ((mode-function (nth 0 mode))
1720 (pretty-minor-mode (nth 1 mode))
1721 (indicator (nth 2 mode)))
1722 (save-excursion
1723 (goto-char (point-max))
1724 (princ "\n\f\n")
1725 (push (point-marker) help-button-cache)
1726 ;; Document the minor modes fully.
1727 (insert-text-button
1728 pretty-minor-mode 'type 'help-function
1729 'help-args (list mode-function)
1730 'button '(t))
1731 (princ (format " minor mode (%s):\n"
1732 (if (zerop (length indicator))
1733 "no indicator"
1734 (format "indicator%s"
1735 indicator))))
1736 (princ (help-split-fundoc (documentation mode-function)
1737 nil 'doc)))
1738 (insert-button pretty-minor-mode
1739 'action (car help-button-cache)
1740 'follow-link t
1741 'help-echo "mouse-2, RET: show full information")
1742 (newline)))
1743 (forward-line -1)
1744 (fill-paragraph nil)
1745 (forward-line 1))
1746
1747 (princ "\n(Information about these minor modes follows the major mode info.)\n\n"))
1748 ;; Document the major mode.
1749 (let ((mode mode-name))
1750 (with-current-buffer standard-output
1751 (let ((start (point)))
1752 (insert (format-mode-line mode nil nil buffer))
1753 (add-text-properties start (point) '(face bold)))))
1754 (princ " mode")
1755 (let* ((mode major-mode)
1756 (file-name (find-lisp-object-file-name mode nil)))
1757 (when file-name
1758 (princ (format-message " defined in `%s'"
1759 (help-fns-short-filename file-name)))
1760 ;; Make a hyperlink to the library.
1761 (with-current-buffer standard-output
1762 (save-excursion
1763 (re-search-backward (substitute-command-keys "`\\([^`']+\\)'")
1764 nil t)
1765 (help-xref-button 1 'help-function-def mode file-name)))))
1766 (princ ":\n")
1767 (princ (help-split-fundoc (documentation major-mode) nil 'doc)))))
1768 ;; For the sake of IELM and maybe others
1769 nil)
1662 1770
1663;;; Replacements for old lib-src/ programs. Don't seem especially useful. 1771;;; Replacements for old lib-src/ programs. Don't seem especially useful.
1664 1772
diff --git a/lisp/help.el b/lisp/help.el
index 45cbaad4e8b..e40ed479e0d 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -879,114 +879,6 @@ current buffer."
879 (princ ", which is ") 879 (princ ", which is ")
880 (describe-function-1 defn))))))) 880 (describe-function-1 defn)))))))
881 881
882(defun describe-mode (&optional buffer)
883 "Display documentation of current major mode and minor modes.
884A brief summary of the minor modes comes first, followed by the
885major mode description. This is followed by detailed
886descriptions of the minor modes, each on a separate page.
887
888For this to work correctly for a minor mode, the mode's indicator
889variable \(listed in `minor-mode-alist') must also be a function
890whose documentation describes the minor mode.
891
892If called from Lisp with a non-nil BUFFER argument, display
893documentation for the major and minor modes of that buffer."
894 (interactive "@")
895 (unless buffer (setq buffer (current-buffer)))
896 (help-setup-xref (list #'describe-mode buffer)
897 (called-interactively-p 'interactive))
898 ;; For the sake of help-do-xref and help-xref-go-back,
899 ;; don't switch buffers before calling `help-buffer'.
900 (with-help-window (help-buffer)
901 (with-current-buffer buffer
902 (let (minor-modes)
903 ;; Older packages do not register in minor-mode-list but only in
904 ;; minor-mode-alist.
905 (dolist (x minor-mode-alist)
906 (setq x (car x))
907 (unless (memq x minor-mode-list)
908 (push x minor-mode-list)))
909 ;; Find enabled minor mode we will want to mention.
910 (dolist (mode minor-mode-list)
911 ;; Document a minor mode if it is listed in minor-mode-alist,
912 ;; non-nil, and has a function definition.
913 (let ((fmode (or (get mode :minor-mode-function) mode)))
914 (and (boundp mode) (symbol-value mode)
915 (fboundp fmode)
916 (let ((pretty-minor-mode
917 (if (string-match "\\(\\(-minor\\)?-mode\\)?\\'"
918 (symbol-name fmode))
919 (capitalize
920 (substring (symbol-name fmode)
921 0 (match-beginning 0)))
922 fmode)))
923 (push (list fmode pretty-minor-mode
924 (format-mode-line (assq mode minor-mode-alist)))
925 minor-modes)))))
926 ;; Narrowing is not a minor mode, but its indicator is part of
927 ;; mode-line-modes.
928 (when (buffer-narrowed-p)
929 (push '(narrow-to-region "Narrow" " Narrow") minor-modes))
930 (setq minor-modes
931 (sort minor-modes
932 (lambda (a b) (string-lessp (cadr a) (cadr b)))))
933 (when minor-modes
934 (princ "Enabled minor modes:\n")
935 (make-local-variable 'help-button-cache)
936 (with-current-buffer standard-output
937 (dolist (mode minor-modes)
938 (let ((mode-function (nth 0 mode))
939 (pretty-minor-mode (nth 1 mode))
940 (indicator (nth 2 mode)))
941 (save-excursion
942 (goto-char (point-max))
943 (princ "\n\f\n")
944 (push (point-marker) help-button-cache)
945 ;; Document the minor modes fully.
946 (insert-text-button
947 pretty-minor-mode 'type 'help-function
948 'help-args (list mode-function)
949 'button '(t))
950 (princ (format " minor mode (%s):\n"
951 (if (zerop (length indicator))
952 "no indicator"
953 (format "indicator%s"
954 indicator))))
955 (princ (help-split-fundoc (documentation mode-function)
956 nil 'doc)))
957 (insert-button pretty-minor-mode
958 'action (car help-button-cache)
959 'follow-link t
960 'help-echo "mouse-2, RET: show full information")
961 (newline)))
962 (forward-line -1)
963 (fill-paragraph nil)
964 (forward-line 1))
965
966 (princ "\n(Information about these minor modes follows the major mode info.)\n\n"))
967 ;; Document the major mode.
968 (let ((mode mode-name))
969 (with-current-buffer standard-output
970 (let ((start (point)))
971 (insert (format-mode-line mode nil nil buffer))
972 (add-text-properties start (point) '(face bold)))))
973 (princ " mode")
974 (let* ((mode major-mode)
975 (file-name (find-lisp-object-file-name mode nil)))
976 (when file-name
977 (princ (format-message " defined in `%s'"
978 (file-name-nondirectory file-name)))
979 ;; Make a hyperlink to the library.
980 (with-current-buffer standard-output
981 (save-excursion
982 (re-search-backward (substitute-command-keys "`\\([^`']+\\)'")
983 nil t)
984 (help-xref-button 1 'help-function-def mode file-name)))))
985 (princ ":\n")
986 (princ (help-split-fundoc (documentation major-mode) nil 'doc)))))
987 ;; For the sake of IELM and maybe others
988 nil)
989
990(defun search-forward-help-for-help () 882(defun search-forward-help-for-help ()
991 "Search forward \"help window\"." 883 "Search forward \"help window\"."
992 (interactive) 884 (interactive)