unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 57813@debbugs.gnu.org
Subject: bug#57813: Icon images are non-functional
Date: Thu, 13 Oct 2022 10:51:35 +0300	[thread overview]
Message-ID: <86sfjstan4.fsf@mail.linkov.net> (raw)
In-Reply-To: <86pmfxlp7s.fsf@mail.linkov.net> (Juri Linkov's message of "Wed,  14 Sep 2022 22:40:07 +0300")

[-- Attachment #1: Type: text/plain, Size: 598 bytes --]

This patch distinguishes two cases of using buttons in outline-minor-mode:

1. when buttons can be inserted to a read-only buffer,
   then it's possible to move point to the inserted button
   and use it by keyboard;

2. when the buffer is editable and should not be modified
   to insert buttons, when the only way to display buttons
   is with a before-string overlay.  The disadvantage is that
   buttons can be used only by clicking mouse.

A new variable 'outline-read-only' is added here to allow
setting it explicitly in buffers that can be modified
to insert buttons like the Help buffer:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: outline-read-only.patch --]
[-- Type: text/x-diff, Size: 4277 bytes --]

diff --git a/lisp/help.el b/lisp/help.el
index b4b9120da3..713467c9b2 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -608,13 +608,8 @@ describe-bindings
           (setq-local outline-heading-end-regexp ":\n")
           (setq-local outline-level (lambda () 1))
           (setq-local outline-minor-mode-cycle t
-                      outline-minor-mode-highlight t)
+                      outline-minor-mode-highlight t
+                      outline-read-only t)
           (outline-minor-mode 1)
           (save-excursion
             (goto-char (point-min))
diff --git a/lisp/outline.el b/lisp/outline.el
index b87d3ac5e7..5a65c6c8e5 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -295,6 +295,9 @@ outline-minor-mode-use-buttons
 (defvar-local outline--use-buttons nil
   "Non-nil when buffer displays clickable buttons on the headings.")
 
+(defvar-local outline-read-only nil
+  "Non-nil when it's allowed to modify buffer to insert buttons.")
+
 (defvar-local outline--use-rtl nil
   "Non-nil when direction of clickable buttons is right-to-left.")
 
@@ -1652,18 +1655,24 @@ outline--make-button-overlay
                                    (if outline--use-rtl
                                        'outline-close-rtl
                                      'outline-close)
-                                 'outline-open)))
-          (inhibit-read-only t))
+                                 'outline-open))))
       ;; In editing buffers we use overlays only, but in other buffers
       ;; we use a mix of text properties, text and overlays to make
       ;; movement commands work more logically.
-      (when (derived-mode-p 'special-mode)
-        (put-text-property (point) (1+ (point)) 'face (plist-get icon 'face)))
-      (if-let ((image (plist-get icon 'image)))
-          (overlay-put o 'display image)
-        (overlay-put o 'display (concat (plist-get icon 'string)
-                                        (string (char-after (point)))))
-        (overlay-put o 'face (plist-get icon 'face))))
+      (if outline-read-only
+          (let ((inhibit-read-only t))
+            (put-text-property (point) (1+ (point)) 'face (plist-get icon 'face))
+            (if-let ((image (plist-get icon 'image)))
+                (overlay-put o 'display image)
+              (overlay-put o 'display (concat (plist-get icon 'string)
+                                              (string (char-after (point)))))
+              (overlay-put o 'face (plist-get icon 'face))))
+        (overlay-put
+         o 'before-string
+         (propertize " "
+                     'display
+                     (or (plist-get icon 'image)
+                         (plist-get icon 'string))))))
     o))
 
 (defun outline--make-margin-overlay (type)
@@ -1699,7 +1713,7 @@ outline--insert-open-button
       (beginning-of-line)
       (if use-margins
           (outline--make-margin-overlay 'open)
-        (when (derived-mode-p 'special-mode)
+        (when outline-read-only
           (let ((inhibit-read-only t))
             (insert "  ")
             (beginning-of-line)))
@@ -1716,7 +1730,7 @@ outline--insert-close-button
       (beginning-of-line)
       (if use-margins
           (outline--make-margin-overlay 'close)
-        (when (derived-mode-p 'special-mode)
+        (when outline-read-only
           (let ((inhibit-read-only t))
             (insert "  ")
             (beginning-of-line)))
diff --git a/lisp/textmodes/emacs-news-mode.el b/lisp/textmodes/emacs-news-mode.el
index d9decae4df..f7f56eb047 100644
--- a/lisp/textmodes/emacs-news-mode.el
+++ b/lisp/textmodes/emacs-news-mode.el
@@ -73,11 +73,7 @@ emacs-news-mode-font-lock-keywords
 
 (defun emacs-news--mode-common ()
   (setq-local font-lock-defaults '(emacs-news-mode-font-lock-keywords t))
-  ;; This `outline-regexp' matches leading spaces inserted
-  ;; by the current implementation of `outline-minor-mode-use-buttons'.
-  (setq-local outline-regexp "\\(?: +\\)?\\(\\*+\\) "
-              outline-level (lambda () (length (match-string 1)))
-              outline-minor-mode-cycle t
+  (setq-local outline-minor-mode-cycle t
               outline-minor-mode-highlight 'append)
   (outline-minor-mode)
   (setq-local imenu-generic-expression outline-imenu-generic-expression)

  parent reply	other threads:[~2022-10-13  7:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14 19:40 bug#57813: Icon images are non-functional Juri Linkov
2022-09-15 16:30 ` Juri Linkov
2022-09-15 16:36   ` Juri Linkov
2022-09-15 16:53     ` Eli Zaretskii
2022-09-15 17:35       ` Juri Linkov
2022-09-15 18:32         ` Eli Zaretskii
2022-09-15 19:46           ` Juri Linkov
2022-09-16 16:16             ` Juri Linkov
2022-09-15 19:53   ` Juri Linkov
2022-09-16  5:29     ` Eli Zaretskii
2022-09-16  7:09       ` Juri Linkov
2022-09-17 19:37         ` Juri Linkov
2022-09-18  5:08           ` Eli Zaretskii
2022-09-18 18:46             ` Juri Linkov
2022-09-18  5:17           ` Eli Zaretskii
2022-09-18 19:06             ` Juri Linkov
2022-09-19 12:12               ` Eli Zaretskii
2022-09-19 19:37                 ` Juri Linkov
2022-09-20 11:31                   ` Eli Zaretskii
2022-09-20 16:12                     ` Juri Linkov
2022-09-23 15:48     ` Juri Linkov
2022-09-23 16:26       ` Lars Ingebrigtsen
2022-09-24 17:17         ` Juri Linkov
2022-10-12 14:42           ` Max Brieiev
2022-10-12 18:55             ` Juri Linkov
2022-10-23 16:55               ` Juri Linkov
2022-10-13  7:51 ` Juri Linkov [this message]
2022-10-18 18:14   ` Juri Linkov
2022-10-18 18:35     ` Juri Linkov
2022-10-19  6:44       ` Juri Linkov
2022-10-22 18: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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86sfjstan4.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=57813@debbugs.gnu.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).