How to permanently enable the hs-minor-mode in emacs

China☆狼群 提交于 2020-01-13 07:55:35

问题


I am using thhs code in the .emacs file to permanently enable the hs-minor-mode and to change the shortcut:

(setq-default hs-minor-mode t)
(global-set-key (kbd "C-c C-h") (kbd "C-c @ C-h"))         ;;hiding block of code
(global-set-key (kbd "C-c C-r") (kbd "C-c @ C-s"))         ;;revealing block of code

But the mode is not activated automatically. what should i do?


回答1:


If you want it to be truly global, this does the trick:

(define-globalized-minor-mode global-hs-minor-mode
  hs-minor-mode hs-minor-mode)

(global-hs-minor-mode 1)



回答2:


You can turn on hs-minor-mode for a specific mode like C, C++ mode using c-mode-common-hook.

(add-hook 'c-mode-common-hook #'hs-minor-mode)

In Emacs 24 or later, you can turn it on in all programming modes using prog-mode-hook.

(add-hook 'prog-mode-hook #'hs-minor-mode)



回答3:


If you want to enable it everywhere, and start the buffer with the code folded by hs-hide-all, do

(defun my-hide-all()
  (interactive)
  (hs-minor-mode)
  (hs-hide-all))
(add-hook 'prog-mode-hook 'my-hide-all)


来源:https://stackoverflow.com/questions/12763566/how-to-permanently-enable-the-hs-minor-mode-in-emacs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!