When I open my init.el
in Vim, I want folding on comments. However, the code I made for this has broken syntax highlighting. This is not the desired result.
Here is what I used, in my .vimrc
:
augroup filetype_el
autocmd!
autocmd FileType el setlocal foldmethod=marker foldmarker=;;;,;;+
augroup END
au BufRead,BufNewFile *.el set filetype=el
This breaks syntax highlighting for me.
Solution:
With Ben's explanation, I realize I should have used lisp
as filetype, and not el
. Here is the working code:
augroup filetype_lisp
autocmd!
autocmd FileType lisp setlocal foldmethod=marker foldmarker=;;;,;;+
augroup END
Now I have folding and syntax highlighting.
Sample file:
In a .el
file, I want the following to have folding and syntax highlighting when opened from Vim.
;;; config folding
;;;; outline & outshine
;; when a .el file is opened, use outline-minor-mode
(add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
;; gives my init.el nice folding and keybinding defaults
(when (locate-library "outshine")
(autoload 'outshine-hook-function "outshine")
(add-hook 'emacs-lisp-mode-hook 'outshine-hook-function))
(setq outshine-startup-folded-p t)
;;+
;;;; vimrc mode, hideshow
;; because we sometimes view our .vim and .vimrc files from emacs
(when (locate-library "vimrc-mode")
(add-to-list 'auto-mode-alist '(".vim\\(rc\\)?$" . vimrc-mode))
(add-to-list 'hs-special-modes-alist '(vimrc-mode "{{{" "}}}" nil nil))
(add-hook 'vimrc-mode-hook '(lambda ()
(hs-minor-mode)
(hs-hide-all)))
(autoload 'hs-minor-mode "hideshow" nil t)
(eval-after-load 'hideshow
'(define-key hs-minor-mode-map (kbd "TAB") 'hs-toggle-hiding)))
;;+
;;+
(I will consider ways to get rid of the ;;+
s, someday.)
Edit: Someday has come, Vim, foldexpr, like folding in outshine.el effect on init.el - Stack Overflow. I can now omit the ;;+
from my init.el
.