unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39354: enhancement request: hideshow should handle derived modes
@ 2020-01-30  9:24 Tobias Zawada
  2020-08-21 12:42 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Zawada @ 2020-01-30  9:24 UTC (permalink / raw)
  To: 39354

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#39354: enhancement request: hideshow should handle derived modes
  2020-01-30  9:24 bug#39354: enhancement request: hideshow should handle derived modes Tobias Zawada
@ 2020-08-21 12:42 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-21 12:42 UTC (permalink / raw)
  To: Tobias Zawada; +Cc: 39354

Tobias Zawada <i_inbox@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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-21 12:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-30  9:24 bug#39354: enhancement request: hideshow should handle derived modes Tobias Zawada
2020-08-21 12:42 ` Lars Ingebrigtsen

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).