From: Masatake YAMATO <jet@gyve.org>
Subject: Re: |PATCH| describe-minor-mode and describe-minor-mode-from-indicator
Date: Tue, 21 Jan 2003 01:06:55 +0900 (JST) [thread overview]
Message-ID: <20030121.010655.21600771.jet@gyve.org> (raw)
In-Reply-To: <E18aQ7q-0006LW-00@fencepost.gnu.org>
I've updated my patch.
I wrote:
1. M-x describe-minor-mode
The user of describe-minor-mode can give its argument
with completion. The completion table is built from the
name of minor modes activated on the current buffer.
2. M-x describe-minor-mode-from-indicator
Almost the same as describe-minor-mode but the user
can pass an indicator instead of minor mode name to
get help. I could not implment completion.
(You will be not satisfied with "without completion".)
3. I added "Describe `MinorMode'" menu item to "Minor Modes"
popup menu. The user can get help about a minor mode with mouse-3.
Richard Stallman wrote:
This is a very useful feature. It could be more useful if the user
could click on a minor mode name in the mode line and get a
description of it. This could work for mahor modes too. Right now
only mouse-3 is used on this part of the mode line.
(It is not hard to call completing-read--did you find this
difficult?).
Thank you for your comment.
The update patch supports:
2' M-x describe-minor-mode-from-indicator
uses completing-read to read indicator.
3' Added popup menu for major mode. I introduced just another
popup menu for major mode.
Tell me when I should write ChangeLog entry:)
Masatake YAMATO
Index: help.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help.el,v
retrieving revision 1.255
diff -u -r1.255 help.el
--- help.el 13 Jan 2003 08:04:46 -0000 1.255
+++ help.el 20 Jan 2003 17:09:59 -0000
@@ -611,6 +611,75 @@
(setq minor-modes (cdr minor-modes))))
(print-help-return-message))))
+(defun describe-minor-mode (minor-mode)
+ "Display documentation of a minor mode given as MINOR-MODE."
+ (interactive (list (intern (completing-read
+ "Minor mode: "
+ (delete nil (mapcar
+ (function (lambda (x)
+ (if (eval (car x))
+ (symbol-name (car x)))))
+ minor-mode-alist))))))
+ (if (fboundp minor-mode)
+ (describe-function minor-mode)
+ (describe-variable minor-mode)))
+
+(defun describe-minor-mode-from-indicator (indicator)
+ "Display documentation of a minor mode specified by INDICATOR."
+ (interactive (list
+ (completing-read
+ "Minor mode indicator: "
+ (delete nil
+ (mapcar
+ #'(lambda (x)
+ (if (eval (car x))
+ (let ((i (expand-minor-mode-indicator-object (cadr x))))
+ (if (and (< 0 (length i))
+ (string= " " (substring i 0 1)))
+ (substring i 1)
+ i))))
+ minor-mode-alist)))))
+ (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
+ (if minor-mode
+ (describe-minor-mode minor-mode)
+ (error "Cannot find minor mode for `%s'" indicator))))
+
+(defun lookup-minor-mode-from-indicator (indicator)
+ "Return a minor mode symbol from its indicator on the modeline."
+ (if (and (< 0 (length indicator))
+ (not (string= " " (substring indicator 0 1))))
+ (setq indicator (concat " " indicator)))
+ (let ((minor-modes minor-mode-alist)
+ result)
+ (while minor-modes
+ (let* ((minor-mode (car (car minor-modes)))
+ (anindicator (car (cdr (car minor-modes)))))
+ (setq anindicator (expand-minor-mode-indicator-object anindicator))
+ (if (and (stringp anindicator)
+ (string= anindicator indicator))
+ (setq result minor-mode
+ minor-modes nil)
+ (setq minor-modes (cdr minor-modes)))))
+ result))
+
+(defun expand-minor-mode-indicator-object (obj)
+ "Expand OBJ that represents a minor-mode indicator.
+cdr part of a `minor-mode-alist' element(indicator object) is the
+indicator of minor mode that is in car part. Normally indicator
+object is a string. However, in some case it is more compound object
+like cons cell. This function tries to make the compound object a string."
+ ;; copied from describe-mode
+ (while (and obj (symbolp obj)
+ (boundp obj)
+ (not (eq obj (symbol-value obj))))
+ (setq obj (symbol-value obj)))
+ ;; eval :eval
+ (if (and (consp obj)
+ (keywordp (car obj))
+ (eq :eval (car obj)))
+ (setq obj (eval (cadr obj))))
+ obj)
+
\f
;;; Automatic resizing of temporary buffers.
Index: bindings.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.112
diff -u -r1.112 bindings.el
--- bindings.el 21 Dec 2002 20:19:37 -0000 1.112
+++ bindings.el 20 Jan 2003 17:09:59 -0000
@@ -249,6 +249,9 @@
(make-variable-buffer-local 'mode-line-modified)
+(defvar mode-line-major-mode-keymap nil "\
+Keymap to display on major mode.")
+
;; Actual initialization is below.
(defvar mode-line-position nil
"Mode-line control for displaying line number, column number and fraction.")
@@ -257,12 +260,17 @@
"Mode-line control for displaying major and minor modes.")
(defvar mode-line-minor-mode-keymap nil "\
-Keymap to display on major and minor modes.")
+Keymap to display on minor modes.")
+
+;; Menu of major mode.
+(let ((map (make-sparse-keymap)))
+ (define-key map [mode-line down-mouse-3] 'mode-line-major-mode-menu-1)
+ (setq mode-line-major-mode-keymap map))
;; Menu of minor modes.
(let ((map (make-sparse-keymap)))
- (define-key map [mode-line down-mouse-3] 'mode-line-mode-menu-1)
- (define-key map [header-line down-mouse-3] 'mode-line-mode-menu-1)
+ (define-key map [mode-line down-mouse-3] 'mode-line-minor-mode-menu-1)
+ (define-key map [header-line down-mouse-3] 'mode-line-minor-mode-menu-1)
(setq mode-line-minor-mode-keymap map))
(let* ((help-echo
@@ -292,8 +300,13 @@
(setq-default mode-line-modes
(list
(propertize "%[(" 'help-echo help-echo)
- `(:propertize ("" mode-name mode-line-process minor-mode-alist)
- help-echo "mouse-3: minor mode menu"
+ ;; major mode
+ `(:propertize ("" mode-name)
+ help-echo "mouse-3: major mode menu"
+ local-map ,mode-line-major-mode-keymap)
+ ;; minor modes
+ `(:propertize ("" mode-line-process minor-mode-alist)
+ help-echo "mouse-3: minor modes menu"
local-map ,mode-line-minor-mode-keymap)
(propertize "%n" 'help-echo "mouse-2: widen"
'local-map (make-mode-line-mouse-map
@@ -359,63 +372,104 @@
(interactive)
(switch-to-buffer (other-buffer)))
-(defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\
-Menu of mode operations in the mode line.")
+(defvar mode-line-major-mode-menu (make-sparse-keymap "Major Mode") "\
+Menu of major mode operations in the mode line.")
-(defun mode-line-mode-menu-1 (event)
- (interactive "e")
+(defvar mode-line-minor-mode-menu (make-sparse-keymap "Minor Modes") "\
+Menu of minor modes operations in the mode line.")
+
+(defun mode-line-mode-menu-1 (event menu)
(save-selected-window
(select-window (posn-window (event-start event)))
- (let* ((selection (mode-line-mode-menu event))
- (binding (and selection (lookup-key mode-line-mode-menu
+ (let* ((selection (funcall menu event))
+ (binding (and selection (lookup-key (eval menu)
(vector (car selection))))))
(if binding
(call-interactively binding)))))
+
+(defun mode-line-major-mode-menu-1 (event)
+ (interactive "e")
+ (mode-line-mode-menu-1 event 'mode-line-major-mode-menu))
+
+(defun mode-line-minor-mode-menu-1 (event)
+ (interactive "e")
+ (mode-line-mode-menu-1 event 'mode-line-minor-mode-menu))
(defmacro bound-and-true-p (var)
"Return the value of symbol VAR if it is bound, else nil."
`(and (boundp (quote ,var)) ,var))
-(define-key mode-line-mode-menu [overwrite-mode]
+(define-key mode-line-major-mode-menu [describe-mode]
+ `(menu-item ,'(format "Describe `%s'"
+ mode-line-mode-menu-grab-mode-indicator)
+ describe-mode
+ :visible (and mode-line-mode-menu-grab-mode-indicator
+ (not (string= " " (substring mode-line-mode-menu-grab-mode-indicator 0 1))))))
+
+(define-key mode-line-minor-mode-menu [overwrite-mode]
`(menu-item ,(purecopy "Overwrite (Ovwrt)") overwrite-mode
:button (:toggle . overwrite-mode)))
-(define-key mode-line-mode-menu [outline-minor-mode]
+(define-key mode-line-minor-mode-menu [outline-minor-mode]
`(menu-item ,(purecopy "Outline (Outl)") outline-minor-mode
:button (:toggle . (bound-and-true-p outline-minor-mode))))
-(define-key mode-line-mode-menu [line-number-mode]
+(define-key mode-line-minor-mode-menu [line-number-mode]
`(menu-item ,(purecopy "Line number") line-number-mode
:button (:toggle . line-number-mode)))
-(define-key mode-line-mode-menu [highlight-changes-mode]
+(define-key mode-line-minor-mode-menu [highlight-changes-mode]
`(menu-item ,(purecopy "Highlight changes (Chg)") highlight-changes-mode
:button (:toggle . highlight-changes-mode)))
-(define-key mode-line-mode-menu [glasses-mode]
+(define-key mode-line-minor-mode-menu [glasses-mode]
`(menu-item ,(purecopy "Glasses (o^o)") glasses-mode
:button (:toggle . (bound-and-true-p glasses-mode))))
-(define-key mode-line-mode-menu [hide-ifdef-mode]
+(define-key mode-line-minor-mode-menu [hide-ifdef-mode]
`(menu-item ,(purecopy "Hide ifdef (Ifdef)") hide-ifdef-mode
:button (:toggle . (bound-and-true-p hide-ifdef-mode))))
-(define-key mode-line-mode-menu [font-lock-mode]
+(define-key mode-line-minor-mode-menu [font-lock-mode]
`(menu-item ,(purecopy "Font Lock") font-lock-mode
:button (:toggle . font-lock-mode)))
-(define-key mode-line-mode-menu [flyspell-mode]
+(define-key mode-line-minor-mode-menu [flyspell-mode]
`(menu-item ,(purecopy "Flyspell (Fly)") flyspell-mode
:button (:toggle . (bound-and-true-p flyspell-mode))))
-(define-key mode-line-mode-menu [column-number-mode]
+(define-key mode-line-minor-mode-menu [column-number-mode]
`(menu-item ,(purecopy "Column number") column-number-mode
:button (:toggle . column-number-mode)))
-(define-key mode-line-mode-menu [auto-fill-mode]
+(define-key mode-line-minor-mode-menu [auto-fill-mode]
`(menu-item ,(purecopy "Auto Fill (Fill)") auto-fill-mode
:button (:toggle . auto-fill-function)))
-(define-key mode-line-mode-menu [auto-revert-mode]
+(define-key mode-line-minor-mode-menu [auto-revert-mode]
`(menu-item ,(purecopy "Auto revert (ARev)") auto-revert-mode
:button (:toggle . auto-revert-mode)))
-(define-key mode-line-mode-menu [abbrev-mode]
+(define-key mode-line-minor-mode-menu [abbrev-mode]
`(menu-item ,(purecopy "Abbrev (Abbrev)") abbrev-mode
:button (:toggle . abbrev-mode)))
-(defun mode-line-mode-menu (event)
+(autoload 'describe-minor-mode-from-indicator "help"
+ "Display documentation of a minor mode given as MINOR-MODE." t)
+(define-key mode-line-minor-mode-menu [describe-minor-mode]
+ `(menu-item ,'(format "Describe `%s'"
+ (substring mode-line-mode-menu-grab-mode-indicator 1))
+ (lambda ()
+ (interactive)
+ (describe-minor-mode-from-indicator
+ mode-line-mode-menu-grab-mode-indicator))
+ :visible (and mode-line-mode-menu-grab-mode-indicator
+ (string= " " (substring mode-line-mode-menu-grab-mode-indicator 0 1)))))
+
+(defun get-mode-indicator-from-event (event)
+ (car (nth 4 (car (cdr event)))))
+(defvar mode-line-mode-menu-grab-mode-indicator nil)
+
+(defun mode-line-mode-menu (event menu)
+ (setq mode-line-mode-menu-grab-mode-indicator (get-mode-indicator-from-event event))
+ (x-popup-menu event menu))
+
+(defun mode-line-major-mode-menu (event)
+ (interactive "@e")
+ (mode-line-mode-menu event mode-line-major-mode-menu))
+
+(defun mode-line-minor-mode-menu (event)
(interactive "@e")
- (x-popup-menu event mode-line-mode-menu))
+ (mode-line-mode-menu event mode-line-minor-mode-menu))
;; Add menu of buffer operations to the buffer identification part
;; of the mode line.or header line.
next prev parent reply other threads:[~2003-01-20 16:06 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-18 7:35 |PATCH| describe-minor-mode and describe-minor-mode-from-indicator Masatake YAMATO
2003-01-18 14:12 ` Masatake YAMATO
2003-01-20 0:49 ` Richard Stallman
2003-01-20 16:06 ` Masatake YAMATO [this message]
2003-01-21 6:00 ` Masatake YAMATO
2003-01-22 9:59 ` Richard Stallman
2003-01-23 17:40 ` Masatake YAMATO
2003-01-25 19:23 ` Richard Stallman
2003-01-30 16:04 ` Masatake YAMATO
[not found] ` <E18eghV-0000MM-00@fencepost.gnu.org>
2003-03-30 7:51 ` Masatake YAMATO
2003-03-31 15:51 ` Stefan Monnier
2003-03-31 16:35 ` Masatake YAMATO
2003-03-31 17:14 ` Stefan Monnier
2003-04-01 9:38 ` Richard Stallman
2003-04-01 12:27 ` Masatake YAMATO
2003-04-01 12:58 ` Masatake YAMATO
2003-04-02 9:19 ` Richard Stallman
2003-04-07 15:46 ` Masatake YAMATO
2003-04-08 2:30 ` Richard Stallman
2003-04-10 8:36 ` Masatake YAMATO
2003-04-10 13:21 ` Stefan Monnier
2003-04-11 8:51 ` Richard Stallman
2003-04-11 19:30 ` Masatake YAMATO
2003-04-12 17:08 ` Richard Stallman
2003-04-02 9:18 ` Richard Stallman
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=20030121.010655.21600771.jet@gyve.org \
--to=jet@gyve.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.