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.bugs Subject: bug#45147: Org-like cycling in outline-minor-mode Date: Wed, 16 Dec 2020 22:28:51 +0200 Organization: LINKOV.NET Message-ID: <87r1npldlw.fsf@mail.linkov.net> References: <874kkuyhfx.fsf@mail.linkov.net> <87lfe6vjb0.fsf@mail.linkov.net> <87zh2gyvkv.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="32938"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 45147@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 16 22:06:34 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1kpe0H-0008R5-Qk for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 22:06:33 +0100 Original-Received: from localhost ([::1]:57904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpe0G-0002B0-Ro for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 16:06:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpdzn-00022T-EY for bug-gnu-emacs@gnu.org; Wed, 16 Dec 2020 16:06:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50708) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kpdzm-0006Vz-Sk for bug-gnu-emacs@gnu.org; Wed, 16 Dec 2020 16:06:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kpdzm-00049L-N8 for bug-gnu-emacs@gnu.org; Wed, 16 Dec 2020 16:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Dec 2020 21:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45147 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 45147-submit@debbugs.gnu.org id=B45147.160815271815855 (code B ref 45147); Wed, 16 Dec 2020 21:06:02 +0000 Original-Received: (at 45147) by debbugs.gnu.org; 16 Dec 2020 21:05:18 +0000 Original-Received: from localhost ([127.0.0.1]:34013 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kpdz3-00047f-J7 for submit@debbugs.gnu.org; Wed, 16 Dec 2020 16:05:18 -0500 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:57211) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kpdyx-000473-4G for 45147@debbugs.gnu.org; Wed, 16 Dec 2020 16:05:12 -0500 X-Originating-IP: 91.129.99.98 Original-Received: from mail.gandi.net (m91-129-99-98.cust.tele2.ee [91.129.99.98]) (Authenticated sender: juri@linkov.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 2365DE0003 for <45147@debbugs.gnu.org>; Wed, 16 Dec 2020 21:05:03 +0000 (UTC) In-Reply-To: <87zh2gyvkv.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 14 Dec 2020 22:35:44 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:196222 Archived-At: --=-=-= Content-Type: text/plain As proposed in bug#41198, here is the support for outline-minor-mode in the 'C-h b' Help buffer: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=outline-describe-bindings.patch diff --git a/lisp/help.el b/lisp/help.el index ac5c2f1311..be366439b8 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -509,7 +509,22 @@ describe-bindings ;; Be aware that `describe-buffer-bindings' puts its output into ;; the current buffer. (with-current-buffer (help-buffer) - (describe-buffer-bindings buffer prefix)))) + (describe-buffer-bindings buffer prefix) + + (setq-local outline-regexp ".*:$") + (setq-local outline-level (lambda () 1)) + (setq-local outline-minor-mode-cycle t) + (setq-local outline-minor-mode-highlight t) + (outline-minor-mode +1) + (save-excursion + (let ((inhibit-read-only t)) + (goto-char (point-min)) + (insert "Type TAB or S-TAB on headings to cycle their visibility.\n\n") + ;; Hide the longest body + (when (and (re-search-forward "Key translations" nil t) + (fboundp 'outline-cycle)) + (outline-cycle)))) + (font-lock-ensure)))) ;; This function used to be in keymap.c. (defun describe-bindings-internal (&optional menus prefix) And here is an updated outline.el: diff --git a/lisp/outline.el b/lisp/outline.el index 85f9de4e1b..97aba091c5 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -175,23 +175,40 @@ outline-minor-mode-menu-bar-map outline-mode-menu-bar-map)))))) map)) +(defvar outline-mode-cycle-map + (let ((map (make-sparse-keymap))) + (let ((binding `(menu-item + "" outline-cycle + ;; Only takes effect if point is on a heading. + :filter ,(lambda (cmd) + (when (outline-on-heading-p) cmd))))) + (define-key map (kbd "TAB") binding) + (define-key map [tab] binding) + (define-key map (kbd "") #'outline-cycle-buffer)) + map)) + (defvar outline-mode-map (let ((map (make-sparse-keymap))) + (set-keymap-parent map outline-mode-cycle-map) (define-key map "\C-c" outline-mode-prefix-map) (define-key map [menu-bar] outline-mode-menu-bar-map) - ;; Only takes effect if point is on a heading. - (define-key map (kbd "TAB") - `(menu-item "" outline-cycle - :filter ,(lambda (cmd) - (when (outline-on-heading-p) cmd)))) - (define-key map (kbd "") #'outline-cycle-buffer) map)) (defvar outline-font-lock-keywords '( ;; Highlight headings according to the level. - (eval . (list (concat "^\\(?:" outline-regexp "\\).+") - 0 '(outline-font-lock-face) nil t))) + (eval . (list (concat "^\\(?:" outline-regexp "\\)" + (if (string-match-p "\\$$" outline-regexp) + "" ".+")) + 0 '(if outline-minor-mode-cycle + (if outline-minor-mode-highlight + (list 'face (outline-font-lock-face) 'keymap outline-mode-cycle-map) + (list 'face nil 'keymap outline-mode-cycle-map)) + (outline-font-lock-face)) + nil + (if (or outline-minor-mode-highlight outline-minor-mode-cycle) + 'append + t)))) "Additional expressions to highlight in Outline mode.") (defface outline-1 @@ -305,6 +322,19 @@ outline-minor-mode-prefix (define-key outline-minor-mode-map val outline-mode-prefix-map) (set-default sym val))) +(defvar outline-minor-mode-highlight nil + "Highlight headings in `outline-minor-mode' using font-lock keywords. +Non-nil value works well only when outline font-lock keywords +don't conflict with the major mode's font-lock keywords.") +;;;###autoload(put 'outline-minor-mode-highlight 'safe-local-variable 'booleanp) +(defvar outline-minor-mode-cycle nil + "Enable heading cycle in `outline-minor-mode'. +When point is on a heading line, then typing 'TAB' cycles between `hide all', +`headings only' and `show all' (`outline-cycle'). Typing 'S-TAB' on +a heading line cycles the whole buffer (`outline-cycle-buffer'). +Typing these keys anywhere outside heading lines uses their default bindings.") +;;;###autoload(put 'outline-minor-mode-cycle 'safe-local-variable 'booleanp) + ;;;###autoload (define-minor-mode outline-minor-mode "Toggle Outline minor mode. @@ -314,6 +344,11 @@ outline-minor-mode (cons outline-minor-mode-prefix outline-mode-prefix-map)) (if outline-minor-mode (progn + (when (or outline-minor-mode-highlight outline-minor-mode-cycle) + (unless font-lock-defaults + (setq-local font-lock-defaults '(nil t))) + (font-lock-add-keywords nil outline-font-lock-keywords t) + (font-lock-flush)) ;; Turn off this mode if we change major modes. (add-hook 'change-major-mode-hook (lambda () (outline-minor-mode -1)) @@ -321,6 +356,9 @@ outline-minor-mode (setq-local line-move-ignore-invisible t) ;; Cause use of ellipses for invisible text. (add-to-invisibility-spec '(outline . t))) + (when (or outline-minor-mode-highlight outline-minor-mode-cycle) + (font-lock-remove-keywords nil outline-font-lock-keywords) + (font-lock-flush)) (setq line-move-ignore-invisible nil) ;; Cause use of ellipses for invisible text. (remove-from-invisibility-spec '(outline . t)) --=-=-=--