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: Duplicated outline-cycle binding, and problems with the new one Date: Thu, 06 Jan 2022 20:56:34 +0200 Organization: LINKOV.NET Message-ID: <86a6g87lu5.fsf@mail.linkov.net> References: <9DFDAD07-DBC0-4FAE-A565-D1EE6045E7D8@gmail.com> <86ilv25714.fsf@mail.linkov.net> <86pmp6cohf.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="3444"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Yuan Fu , Emacs developers To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jan 06 20:18:07 2022 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 1n5YGz-0000hq-8b for ged-emacs-devel@m.gmane-mx.org; Thu, 06 Jan 2022 20:18:05 +0100 Original-Received: from localhost ([::1]:55628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5YGx-00053M-R8 for ged-emacs-devel@m.gmane-mx.org; Thu, 06 Jan 2022 14:18:03 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:44986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5YE0-0002Ud-75 for emacs-devel@gnu.org; Thu, 06 Jan 2022 14:15:00 -0500 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:52847) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5YDw-0000I0-S2 for emacs-devel@gnu.org; Thu, 06 Jan 2022 14:14:58 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 9A822200006; Thu, 6 Jan 2022 19:14:48 +0000 (UTC) In-Reply-To: (Stefan Monnier's message of "Wed, 05 Jan 2022 14:21:59 -0500") Received-SPF: pass client-ip=217.70.178.232; envelope-from=juri@linkov.net; helo=relay12.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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" Xref: news.gmane.io gmane.emacs.devel:284338 Archived-At: --=-=-= Content-Type: text/plain >> But diff-mode overrides this binding with diff-mode-shared-map >> where the TAB key is bound to diff-hunk-next, since >> minor-mode-overriding-map-alist takes priority over >> minor-mode-map-alist when diff-mode does this: > > I see. I knew using `minor-mode-overriding-map-alist` in `diff-mode.el` > this way was going to bite us sooner or later. > > Maybe we should use a hook on `read-only-mode` to set/unset > a `diff-mode-read-only` variable so we can add the keymap > (conditionalized on this new `diff-mode-read-only`) to > `minor-mode-map-alist` instead of `minor-mode-overriding-map-alist`. So this is because `minor-mode-map-alist` is not buffer-local. Then this requires changing `(setq buffer-read-only t)` to `(read-only-mode 1)` in diff-related places. Since `read-only-mode` always activates `view-mode` when `view-read-only` is t, it needs let-binding: (let ((view-read-only nil)) (read-only-mode 1)). This will keep the current behavior. Then special-handling of `view-mode` in `diff-mode` is not needed because `view-mode` is higher than `diff-mode-read-only` in `minor-mode-map-alist`, where `diff-mode-read-only` is at the end to not take precedence over `outline-minor-mode`. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=diff-mode-read-only.patch diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index ca8df5d380..63b9549b54 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -1479,6 +1479,12 @@ diff--font-lock-cleanup (defvar whitespace-style) (defvar whitespace-trailing-regexp) +(defvar-local diff-mode-read-only nil) + +(or (assq 'diff-mode-read-only minor-mode-map-alist) + (nconc minor-mode-map-alist + (list (cons 'diff-mode-read-only diff-mode-shared-map)))) + ;;;###autoload (define-derived-mode diff-mode fundamental-mode "Diff" "Major mode for viewing/editing context diffs. @@ -1516,23 +1522,19 @@ diff-mode (diff-setup-whitespace) + (add-hook 'read-only-mode-hook + (lambda () + (setq diff-mode-read-only buffer-read-only)) + nil t) + (if diff-default-read-only - (setq buffer-read-only t)) + (let ((view-read-only nil)) (read-only-mode 1))) ;; setup change hooks (if (not diff-update-on-the-fly) (add-hook 'write-contents-functions #'diff-write-contents-hooks nil t) (make-local-variable 'diff-unhandled-changes) (add-hook 'after-change-functions #'diff-after-change-function nil t) (add-hook 'post-command-hook #'diff-post-command-hook nil t)) - ;; Neat trick from Dave Love to add more bindings in read-only mode: - (let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map))) - (add-to-list 'minor-mode-overriding-map-alist ro-bind) - ;; Turn off this little trick in case the buffer is put in view-mode. - (add-hook 'view-mode-hook - (lambda () - (setq minor-mode-overriding-map-alist - (delq ro-bind minor-mode-overriding-map-alist))) - nil t)) ;; add-log support (setq-local add-log-current-defun-function #'diff-current-defun) (setq-local add-log-buffer-file-name-function diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el index 4abcf6c15a..425155be40 100644 --- a/lisp/vc/diff.el +++ b/lisp/vc/diff.el @@ -182,7 +182,7 @@ diff-no-select " ")) (thisdir default-directory)) (with-current-buffer buf - (setq buffer-read-only t) + (let ((view-read-only nil)) (read-only-mode 1)) (buffer-disable-undo (current-buffer)) (let ((inhibit-read-only t)) (erase-buffer)) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 6041c79efc..600c4561ac 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1817,7 +1826,7 @@ vc-diff-internal ;; Make the *vc-diff* buffer read only, the diff-mode key ;; bindings are nicer for read only buffers. pcl-cvs does the ;; same thing. - (setq buffer-read-only t) + (let ((view-read-only nil)) (read-only-mode 1)) (if (and (zerop (buffer-size)) (not (get-buffer-process (current-buffer)))) ;; Treat this case specially so as not to pop the buffer. --=-=-=--