GNU bug report logs - #39354
enhancement request: hideshow should handle derived modes

Previous Next

Package: emacs;

Reported by: Tobias Zawada <i_inbox <at> tn-home.de>

Date: Thu, 30 Jan 2020 09:25:01 UTC

Severity: wishlist

Tags: fixed, patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 39354 in the body.
You can then email your comments to 39354 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#39354; Package emacs. (Thu, 30 Jan 2020 09:25:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tobias Zawada <i_inbox <at> tn-home.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 30 Jan 2020 09:25:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tobias Zawada <i_inbox <at> tn-home.de>
To: bug-gnu-emacs <at> gnu.org
Subject: enhancement request: hideshow should handle derived modes
Date: Thu, 30 Jan 2020 10:24:35 +0100 (CET)
Hi,
hideshow.el should handle derived modes.
See discussion on emacs.SE about hideshow in sage-shell-mode (link: https://emacs.stackexchange.com/questions/55129/hs-minor-mode-and-sage-shell-mode-derived-from-python-mode#comment86297_55129).

I propose following change on `hs-grok-mode-type` (perma-link:
https://github.com/jwiegley/emacs-release/blob/adfd5933358fdf6715423dee8169eb3cd7d982db/lisp/progmodes/hideshow.el#L666):

@@ -7,7 +7,9 @@
   (if (and (boundp 'comment-start)
            (boundp 'comment-end)
            comment-start comment-end)
-      (let* ((lookup (assoc major-mode hs-special-modes-alist))
+      (let* ((lookup (cl-assoc-if (lambda (mode)
+				    (derived-mode-p major-mode mode))
+				  hs-special-modes-alist))
              (start-elem (or (nth 1 lookup) "\\s(")))
         (if (listp start-elem)
             ;; handle (START-REGEXP MDATA-SELECT)


The new version of `hs-grok-mode-type` in full would be:

(defun hs-grok-mode-type ()
  "Set up hideshow variables for new buffers.
If `hs-special-modes-alist' has information associated with the
current buffer's major mode, use that.
Otherwise, guess start, end and `comment-start' regexps; `forward-sexp'
function; and adjust-block-beginning function."
  (if (and (boundp 'comment-start)
           (boundp 'comment-end)
           comment-start comment-end)
      (let* ((lookup (cl-assoc-if (lambda (mode)
				    (derived-mode-p major-mode mode))
				  hs-special-modes-alist))
             (start-elem (or (nth 1 lookup) "\\s(")))
        (if (listp start-elem)
            ;; handle (START-REGEXP MDATA-SELECT)
            (setq hs-block-start-regexp (car start-elem)
                  hs-block-start-mdata-select (cadr start-elem))
          ;; backwards compatibility: handle simple START-REGEXP
          (setq hs-block-start-regexp start-elem
                hs-block-start-mdata-select 0))
        (setq hs-block-end-regexp (or (nth 2 lookup) "\\s)")
              hs-c-start-regexp (or (nth 3 lookup)
                                    (let ((c-start-regexp
                                           (regexp-quote comment-start)))
                                      (if (string-match " +$" c-start-regexp)
                                          (substring c-start-regexp
                                                     0 (1- (match-end 0)))
                                        c-start-regexp)))
              hs-forward-sexp-func (or (nth 4 lookup) 'forward-sexp)
              hs-adjust-block-beginning (nth 5 lookup)))
    (setq hs-minor-mode nil)
    (error "%s Mode doesn't support Hideshow Minor Mode"
           (format-mode-line mode-name))))


Best regards,
Tobias Zawada




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#39354; Package emacs. (Fri, 21 Aug 2020 12:44:02 GMT) Full text and rfc822 format available.

Message #8 received at 39354 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Tobias Zawada <i_inbox <at> tn-home.de>
Cc: 39354 <at> debbugs.gnu.org
Subject: Re: bug#39354: enhancement request: hideshow should handle derived
 modes
Date: Fri, 21 Aug 2020 14:42:48 +0200
Tobias Zawada <i_inbox <at> tn-home.de> writes:

> hideshow.el should handle derived modes.
> See discussion on emacs.SE about hideshow in sage-shell-mode (link: https://emacs.stackexchange.com/questions/55129/hs-minor-mode-and-sage-shell-mode-derived-from-python-mode#comment86297_55129).
>
> I propose following change on `hs-grok-mode-type` (perma-link:
> https://github.com/jwiegley/emacs-release/blob/adfd5933358fdf6715423dee8169eb3cd7d982db/lisp/progmodes/hideshow.el#L666):

[...]

> -      (let* ((lookup (assoc major-mode hs-special-modes-alist))
> +      (let* ((lookup (cl-assoc-if (lambda (mode)
> +				    (derived-mode-p major-mode mode))
> +				  hs-special-modes-alist))

Makes sense to me, so I've applied your patch to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) patch. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 21 Aug 2020 12:44:02 GMT) Full text and rfc822 format available.

Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 21 Aug 2020 12:44:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 39354 <at> debbugs.gnu.org and Tobias Zawada <i_inbox <at> tn-home.de> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 21 Aug 2020 12:44:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 19 Sep 2020 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 213 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.