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#53981: 28.0.91; shortdoc: Add support for outline-minor-mode Date: Wed, 16 Feb 2022 20:18:35 +0200 Organization: LINKOV.NET Message-ID: <86fsoi29ho.fsf@mail.linkov.net> References: <87czjpso5q.fsf@gnus.org> <87sfsky494.fsf@gmail.com> <875ypgqxzg.fsf@gnus.org> 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="18697"; 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: Daniel Mendler , 53981@debbugs.gnu.org, =?UTF-8?Q?K=C3=A9vin?= Le Gouguec To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 16 19:46:51 2022 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 1nKPKE-0004hl-J8 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Feb 2022 19:46:50 +0100 Original-Received: from localhost ([::1]:35000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nKPKC-00047U-4M for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 16 Feb 2022 13:46:48 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nKPIW-00044g-7I for bug-gnu-emacs@gnu.org; Wed, 16 Feb 2022 13:45:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nKPIV-0003rH-Mo for bug-gnu-emacs@gnu.org; Wed, 16 Feb 2022 13:45:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nKPIV-00064r-MM for bug-gnu-emacs@gnu.org; Wed, 16 Feb 2022 13:45:03 -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 Feb 2022 18:45:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53981 X-GNU-PR-Package: emacs Original-Received: via spool by 53981-submit@debbugs.gnu.org id=B53981.164503709423293 (code B ref 53981); Wed, 16 Feb 2022 18:45:03 +0000 Original-Received: (at 53981) by debbugs.gnu.org; 16 Feb 2022 18:44:54 +0000 Original-Received: from localhost ([127.0.0.1]:49437 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nKPIL-00063d-Vy for submit@debbugs.gnu.org; Wed, 16 Feb 2022 13:44:54 -0500 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:64973) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nKPIK-000636-34 for 53981@debbugs.gnu.org; Wed, 16 Feb 2022 13:44:52 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 8477C40003; Wed, 16 Feb 2022 18:44:44 +0000 (UTC) In-Reply-To: <875ypgqxzg.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 15 Feb 2022 10:29:23 +0100") 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:227046 Archived-At: --=-=-= Content-Type: text/plain > As previously discussed in some other bug report *vague hand wave*, it > makes no sense to use regexps for outline in generated buffers. The > functions that generate the buffers knows what's a heading, and should > mark the headings properly (with text properties), and > outline-minor-mode should just react to these text properties in these > buffers. That was in https://debbugs.gnu.org/31094#40 Is this a promising direction? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=outline-search-function.patch diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 658edd6752..63e799a2be 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -1435,7 +1435,19 @@ shortdoc-mode-map (define-derived-mode shortdoc-mode special-mode "shortdoc" "Mode for shortdoc." - :interactive nil) + :interactive nil + (setq-local outline-level (lambda () (if (eq (char-after) ?\() 2 1))) + (setq-local outline-search-function + (lambda (&optional looking-at) + (save-excursion + (let* ((prop-at (if looking-at + (get-text-property (point) 'shortdoc-section) + t)) + (prop-match (and prop-at (text-property-search-forward 'shortdoc-section)))) + (when prop-match + (set-match-data (list (prop-match-beginning prop-match) + (prop-match-end prop-match))) + t)))))) (defun shortdoc--goto-section (arg sym &optional reverse) (unless (natnump arg) diff --git a/lisp/outline.el b/lisp/outline.el index 012e219fc3..a282237696 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -301,7 +303,9 @@ outline-font-lock-face "Return one of `outline-font-lock-faces' for current level." (save-excursion (goto-char (match-beginning 0)) - (looking-at outline-regexp) + (if outline-search-function + (funcall outline-search-function t) + (looking-at outline-regexp)) (aref outline-font-lock-faces (% (1- (funcall outline-level)) (length outline-font-lock-faces))))) @@ -393,14 +397,19 @@ outline-minor-mode-highlight :safe #'symbolp :version "28.1") +(defvar outline-search-function nil + "Function to search the next outline. +It should be like `re-search-forward' and `looking-at'.") + (defun outline-minor-mode-highlight-buffer () ;; Fallback to overlays when font-lock is unsupported. (save-excursion (goto-char (point-min)) (let ((regexp (concat "^\\(?:" outline-regexp "\\).*$"))) - (while (re-search-forward regexp nil t) - (let ((overlay (make-overlay (match-beginning 0) - (match-end 0)))) + (while (if outline-search-function + (funcall outline-search-function) + (re-search-forward regexp nil t)) + (let ((overlay (make-overlay (match-beginning 0) (match-end 0)))) (overlay-put overlay 'outline-overlay t) (when (or (eq outline-minor-mode-highlight 'override) (and (eq outline-minor-mode-highlight t) @@ -535,7 +544,9 @@ outline-on-heading-p (save-excursion (beginning-of-line) (and (bolp) (or invisible-ok (not (outline-invisible-p))) - (looking-at outline-regexp)))) + (if outline-search-function + (funcall outline-search-function t) + (looking-at outline-regexp))))) (defun outline-insert-heading () "Insert a new heading at same depth at point." --=-=-=--