From: Juri Linkov <juri@linkov.net>
To: Po Lu <luangruo@yahoo.com>
Cc: Dmitry Gutov <dmitry@gutov.dev>, emacs-devel@gnu.org
Subject: Re: master 128ed5c9f17: Add one more mouse-set-point call to functions xref-find-*-at-mouse
Date: Mon, 04 Sep 2023 19:42:40 +0300 [thread overview]
Message-ID: <86pm2xev8n.fsf@mail.linkov.net> (raw)
In-Reply-To: <8634zv7cyg.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 03 Sep 2023 20:34:55 +0300")
[-- Attachment #1: Type: text/plain, Size: 1879 bytes --]
>>> Mind however that many of these commands are also meant to operate from
>>> the mode line lighters, in which case this is precisely the desired
>>> behavior.
>>
>> I see that such events show they originate from 'mode-line',
>> and events from the menu bar contain 'menu-bar'. So maybe
>> it would be sufficient to filter out 'mode-line' and 'menu-bar'.
>
> Instead of checking 'posn-area', much simpler would be to implement this
> only for the context-menu with a new option similar to 'mouse-yank-at-point'.
>
> +(defcustom context-menu-move-point nil
> + "If non-nil, move point to the mouse click before opening context menu."
> + :type 'boolean
> + :version "30.1")
This turned out to be quite useless. Because it's too annoying when
a command that operates on the whole buffer moves point to a random place
where the mouse happened to be clicked.
This means there is a need to distinguish commands for which the context
is the whole buffer from the commands where context is narrowed to the
clicked position.
Two examples:
1. 'outline-hide-body' hides body lines in the whole buffer,
thus should be declared with context of the buffer:
```
(defun outline-hide-body ()
"Hide all body lines in buffer, leaving all headings visible.
Note that this does not hide the lines preceding the first heading line."
(declare (context buffer))
(interactive)
(outline-hide-region-body (point-min) (point-max)))
```
2. 'outline-hide-entry' hides body after the clicked heading,
so should be declared with context of point:
```
(defun outline-hide-entry ()
"Hide the body directly following this heading."
(declare (context point))
(interactive)
(save-excursion
(outline-back-to-heading)
(outline-end-of-heading)
(outline-flag-region (point) (progn (outline-next-preface) (point)) t)))
```
Here is a draft that works surprisingly well:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: declare-context.patch --]
[-- Type: text/x-diff, Size: 2530 bytes --]
diff --git a/lisp/outline.el b/lisp/outline.el
index e6365629197..9874e318afe 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1067,6 +1067,7 @@ outline-isearch-open-invisible
\f
(defun outline-hide-entry ()
"Hide the body directly following this heading."
+ (declare (context point))
(interactive)
(save-excursion
(outline-back-to-heading)
@@ -1094,6 +1095,7 @@ 'show-entry
(defun outline-hide-body ()
"Hide all body lines in buffer, leaving all headings visible.
Note that this does not hide the lines preceding the first heading line."
+ (declare (context buffer))
(interactive)
(outline-hide-region-body (point-min) (point-max)))
diff --git a/lisp/simple.el b/lisp/simple.el
index ff665111a5d..9026f0950c8 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2772,6 +2772,12 @@ command-execute
executing a special event, so ignore the prefix argument and
don't clear it."
(setq debug-on-next-call nil)
+ (when (and (mouse-event-p last-nonmenu-event)
+ (not (memq (posn-area (event-start last-nonmenu-event))
+ '(mode-line menu-bar)))
+ (symbolp this-command)
+ (memq 'point (function-get this-command 'context)))
+ (posn-set-point (event-start last-nonmenu-event)))
(let ((prefixarg (unless special
;; FIXME: This should probably be done around
;; pre-command-hook rather than here!
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index a377ec395e1..24a1d11d960 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -217,6 +217,11 @@ 'byte-run--set-interactive-args
(cadr elem)))
val)))))
+(defalias 'byte-run--set-context
+ #'(lambda (f _args &rest val)
+ (list 'function-put (list 'quote f)
+ ''context (list 'quote val))))
+
;; Add any new entries to info node `(elisp)Declare Form'.
(defvar defun-declarations-alist
(list
@@ -239,7 +244,8 @@ defun-declarations-alist
(list 'speed #'byte-run--set-speed)
(list 'completion #'byte-run--set-completion)
(list 'modes #'byte-run--set-modes)
- (list 'interactive-args #'byte-run--set-interactive-args))
+ (list 'interactive-args #'byte-run--set-interactive-args)
+ (list 'context #'byte-run--set-context))
"List associating function properties to their macro expansion.
Each element of the list takes the form (PROP FUN) where FUN is
a function. For each (PROP . VALUES) in a function's declaration,
[-- Attachment #3: Type: text/plain, Size: 154 bytes --]
PS:
More contexts could be added later, such as a lambda that defines a region.
And a property requiring to move point back after finishing the command.
next prev parent reply other threads:[~2023-09-04 16:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <169344150641.11482.13012085201452768898@vcs2.savannah.gnu.org>
[not found] ` <20230831002506.C0C6DC038B5@vcs2.savannah.gnu.org>
2023-08-31 0:43 ` master 128ed5c9f17: Add one more mouse-set-point call to functions xref-find-*-at-mouse Po Lu
2023-08-31 0:54 ` Dmitry Gutov
2023-08-31 1:10 ` Po Lu
2023-08-31 2:05 ` Dmitry Gutov
2023-08-31 2:51 ` Po Lu
2023-08-31 6:37 ` Juri Linkov
2023-09-01 0:59 ` Po Lu
2023-09-01 6:50 ` Juri Linkov
2023-09-03 17:34 ` Juri Linkov
2023-09-04 16:42 ` Juri Linkov [this message]
2023-08-31 11:03 ` Dmitry Gutov
2023-08-31 11:35 ` Po Lu
2023-08-31 16:38 ` Juri Linkov
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=86pm2xev8n.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=dmitry@gutov.dev \
--cc=emacs-devel@gnu.org \
--cc=luangruo@yahoo.com \
/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.