1 Star 0 Fork 2

zhengchen/emacs

forked from latpaw/emacs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
init-markdown.el 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
redguardtoo 提交于 2013-01-15 23:32 . merged from purcell
(autoload 'markdown-mode "markdown-mode" "Mode for editing Markdown documents" t)
(setq auto-mode-alist
(cons '("\\.\\(md\\|markdown\\)\\'" . markdown-mode) auto-mode-alist))
(defun markdown-imenu-create-index ()
(let* ((root '(nil . nil))
cur-alist
(cur-level 0)
(pattern "^\\(\\(#+\\)[ \t]*\\(.+\\)\\|\\([^# \t\n=-].*\\)\n===+\\|\\([^# \t\n=-].*\\)\n---+\\)$")
(empty-heading "-")
(self-heading ".")
hashes pos level heading)
(save-excursion
(goto-char (point-min))
(while (re-search-forward pattern (point-max) t)
(cond
((setq hashes (match-string-no-properties 2))
(setq heading (match-string-no-properties 3)
pos (match-beginning 1)
level (length hashes)))
((setq heading (match-string-no-properties 4))
(setq pos (match-beginning 4)
level 1))
((setq heading (match-string-no-properties 5))
(setq pos (match-beginning 5)
level 2)))
(let ((alist (list (cons heading pos))))
(cond
((= cur-level level) ; new sibling
(setcdr cur-alist alist)
(setq cur-alist alist))
((< cur-level level) ; first child
(dotimes (i (- level cur-level 1))
(setq alist (list (cons empty-heading alist))))
(if cur-alist
(let* ((parent (car cur-alist))
(self-pos (cdr parent)))
(setcdr parent (cons (cons self-heading self-pos) alist)))
(setcdr root alist)) ; primogenitor
(setq cur-alist alist)
(setq cur-level level))
(t ; new sibling of an ancestor
(let ((sibling-alist (last (cdr root))))
(dotimes (i (1- level))
(setq sibling-alist (last (cdar sibling-alist))))
(setcdr sibling-alist alist)
(setq cur-alist alist))
(setq cur-level level)))))
(cdr root))))
(add-hook 'markdown-mode-hook
'(lambda ()
(setq imenu-create-index-function 'markdown-imenu-create-index)))
(provide 'init-markdown)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cowboy13/emacs.git
git@gitee.com:cowboy13/emacs.git
cowboy13
emacs
emacs
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385