问题
So, for a lisp homework assignment I have, it has a long defparameter expression that's a large data set. What I'm wondering is, does emacs or SLIME have anything to "collapse" that large defparameter into a single line, like, say, MATLAB does?
回答1:
Like Bertfred mentioned, hideshow
works great, and it comes build in with more recent versions of emacs. To use it simply add the following snippet to your init file:
(add-hook 'prog-mode-hook #'hs-minor-mode)
(global-set-key (kbd "C-c <right>") 'hs-show-block)
(global-set-key (kbd "C-c <left>") 'hs-hide-block)
The first line enables the functionality in any major mode associated with programming. Once there, C-c <left>
and C-c <right>
should do what you expect - just be mindful of where point is.
https://www.emacswiki.org/emacs/HideShow
回答2:
There's also a package on Melpa called vimish-fold (or the equivalent evil version of it - evil-vimish-fold).
It is not as "automatic" as hideshow
or outline
in the sense that you have to select the lines you want to fold, but the advantage is that you can fold any lines. And the folds don't disappear the when you close your file.
You can define your keybindings for creating/deleting folds and for unfolding/refolding folds, and there you go!
(global-set-key (kbd "your-keybinding") 'vimish-fold)
(global-set-key (kbd "your-keybinding") 'vimish-fold-delete)
(global-set-key (kbd "your-keybinding") 'vimish-fold-toggle)
来源:https://stackoverflow.com/questions/40156497/is-it-possible-to-collapse-a-function-in-emacs