-
-
Save QiangF/452a1f9fa3decb9c1690aa5a0afcef1b to your computer and use it in GitHub Desktop.
hideshow config for python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'hideshow) | |
(define-key hs-minor-mode-map (kbd "C-^") 'hs-toggle-hiding) | |
(add-hook 'python-mode-hook 'hs-minor-mode) | |
(defun display-code-line-counts (ov) | |
(when (eq 'code (overlay-get ov 'hs)) | |
(overlay-put ov 'display | |
(format " ... [%d]" | |
(count-lines (overlay-start ov) | |
(overlay-end ov)))) | |
(overlay-put ov 'face '(:foreground "yellow green")))) | |
(setq hs-set-up-overlay 'display-code-line-counts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar my/py-hide-show-keywords '("class" "def" "elif" "else" "except" | |
"for" "if" "while" "finally" "try" "with")) | |
(defun my/replace-hs-special () | |
(setq hs-special-modes-alist | |
(remove-if #'(lambda (x) (equal 'python-mode (car x))) | |
hs-special-modes-alist)) | |
(push (list | |
'python-mode | |
(mapconcat #'(lambda (x) (concat "^\\s-*" x "\\>")) | |
my/py-hide-show-keywords "\\|") | |
"^\\s-*" | |
"#" | |
#'(lambda (x) (python-nav-end-of-block)) | |
nil) | |
hs-special-modes-alist) | |
(hs-grok-mode-type)) | |
(add-hook 'python-mode-hook 'my/replace-hs-special) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment