From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel 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 Organization: LINKOV.NET Message-ID: <86pm2xev8n.fsf@mail.linkov.net> References: <169344150641.11482.13012085201452768898@vcs2.savannah.gnu.org> <20230831002506.C0C6DC038B5@vcs2.savannah.gnu.org> <87il8wt52f.fsf@yahoo.com> <583ae120-d016-e9e8-2783-db21c1e018b8@gutov.dev> <87edjkt3sn.fsf@yahoo.com> <6c5251b1-c289-07cf-587d-013c781e31f5@gutov.dev> <8734zzudo7.fsf@yahoo.com> <86edjj7m5j.fsf@mail.linkov.net> <8734zyr9n5.fsf@yahoo.com> <86o7imidzk.fsf@mail.linkov.net> <8634zv7cyg.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16898"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: Dmitry Gutov , emacs-devel@gnu.org To: Po Lu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 04 18:56:58 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qdCsj-0004EM-Qm for ged-emacs-devel@m.gmane-mx.org; Mon, 04 Sep 2023 18:56:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qdCro-0002wc-Dt; Mon, 04 Sep 2023 12:56:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdCrm-0002wP-Ab for emacs-devel@gnu.org; Mon, 04 Sep 2023 12:55:58 -0400 Original-Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qdCrY-000135-Cu for emacs-devel@gnu.org; Mon, 04 Sep 2023 12:55:58 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id AC1F71C0004; Mon, 4 Sep 2023 16:55:38 +0000 (UTC) In-Reply-To: <8634zv7cyg.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 03 Sep 2023 20:34:55 +0300") X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=2001:4b98:dc4:8::225; envelope-from=juri@linkov.net; helo=relay5-d.mail.gandi.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310084 Archived-At: --=-=-= Content-Type: text/plain >>> 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=declare-context.patch 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, --=-=-= Content-Type: text/plain 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. --=-=-=--