emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 128ed5c9f17: Add one more mouse-set-point call to functions x


From: Juri Linkov
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
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

>>> 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:

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
 
 (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,
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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]