0

If I start Emacs 25 with an init file (.emacs) containing

(package-initialize)
(load-library "hideshow")
(add-hook 'python-mode-hook (lambda () (hs-minor-mode 1)) )
(setq hs-minor-mode-hook  'hs-hide-initial-comment-block)

then the initial comments in every Python program I load or view are hidden. I can easily unhide them with hs-toggle-hiding (C-c @ C-c). Yet hiding the comments do not help, but rather get in the way, when the file is brief enough to be displayed in its entirety.

How do I configure hideshow to hide the initial comment block only if the file loaded is longer than a specific number of lines?

1 Answer 1

2

Wrapping the call to hs-minor-mode in a check if the buffer has enough likes for it to make sense should suffice, for instance:

(lambda ()
  (when (> (count-lines (point-min) (point-max)) 25)
    (hs-minor-mode 1)))
5
  • It's likely that this is what the OP wants but be aware that this measures not the buffer size but the size of the current buffer restriction (narrowing). If the buffer size is really wanted then use 0 instead of point-min and buffer-size instead of point-max.
    – Drew
    Jul 29, 2017 at 19:12
  • 1
    I don't think OP wanted to keep short files from using hs-minor-mode all together, but rather just to skip the hs-hide-initial-comment-block step. So something like what you wrote, but for the hs-minor-mode-hook instead.
    – Omar
    Jul 29, 2017 at 23:06
  • @Drew What is the current buffer's restriction? Is it the number of CR/CRLF in the file after the hiding? I meant the number of CR/CRLF in the file as it is on disk, before hiding.
    – Calaf
    Jul 30, 2017 at 12:55
  • @Omar Right. This would also be nice because (I suspect) it would make it brief to do this setup simultaneously for an arbitrary number of language hooks.
    – Calaf
    Jul 30, 2017 at 12:58
  • @Drew I don't think it's likely that the buffer will be narrowed when opened.
    – user12563
    Jul 30, 2017 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.