use*_*576 13 emacs org-mode org-babel
在组织模式文件中,使用如下代码:
#+begin_src emacs-lisp
(add-to-list 'org-tab-before-tab-emulation-hook
(lambda ()
(when (within-the-body-of-a-begin-src-block)
(indent-for-tab-command--as-if-in-lisp-mode))))
#+end_src
Run Code Online (Sandbox Code Playgroud)
我希望TAB键缩进代码,如果它在lisp模式下的缓冲区中.
我需要的是:
Org已经可以根据模式突出显示src块语法,并且TAB挂钩就在那里.这看起来很可行.
小智 31
从Emacs 24.1开始,您现在可以设置以下选项:
(setq org-src-tab-acts-natively t)
Run Code Online (Sandbox Code Playgroud)
......那应该处理所有src块.
小智 12
只需将点移动到代码块并按Cc'
这将在elisp模式中弹出一个缓冲区,语法高亮显示所有...
这是一个粗略的解决方案:
(defun indent-org-src-block-line ()
"Indent the current line of emacs lisp code."
(interactive)
(let ((info (org-babel-get-src-block-info 'light)))
(when info
(let ((lang (nth 0 info)))
(when (string= lang "emacs-lisp")
(let ((indent-line-function 'lisp-indent-line))
(indent-for-tab-command)))))))
(add-to-list 'org-tab-before-tab-emulation-hook
'indent-org-src-block-line)
Run Code Online (Sandbox Code Playgroud)
它只处理 emacs-lisp 块。我只测试了未缩进的 src 块(不是组织默认值)。
一般来说,让一种模式在另一种模式中工作是很困难的——许多键盘命令会发生冲突。但一些更基本的笔画,比如缩进、换行、注释(org 会用 # 注释 lisp 代码,这是错误的),看起来它们可以工作并且会产生最大的影响。