Emacs 插入居中的注释 block

标签 emacs macros latex elisp center

我想为 emacs 创建一个宏,它将插入一个带有一些居中文本的 latex 注释 block ,例如:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%                Comment 1                    %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%           Comment 2 Commenttext 3           %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
emacs-lisp 中是否有可能? ?

最佳答案

Emacs 自带命令 comment-box以此目的。它生成居中的注释框,尽管框的宽度因内容而异。例如,区域围绕以下行设置:

This is a comment

当您调用 M-x comment-box文本转换为:
;;;;;;;;;;;;;;;;;;;;;;;
;; This is a comment ;;
;;;;;;;;;;;;;;;;;;;;;;;

我使用修改后的版本,如果该区域未处于事件状态,则将注释框放置在当前行周围,然后退出注释。它还暂时减少了填充列,因此注释框不会比您的最长行宽:
(defun ty-box-comment (beg end &optional arg) 
  (interactive "*r\np")
  (when (not (region-active-p))
    (setq beg (point-at-bol))
    (setq end (point-at-eol)))
  (let ((fill-column (- fill-column 6)))
    (fill-region beg end))
  (comment-box beg end arg)
  (ty-move-point-forward-out-of-comment))

(defun ty-point-is-in-comment-p ()
  "t if point is in comment or at the beginning of a commented line, otherwise nil"
  (or (nth 4 (syntax-ppss))
      (looking-at "^\\s *\\s<")))

(defun ty-move-point-forward-out-of-comment ()
  "Move point forward until it's no longer in a comment"
  (while (ty-point-is-in-comment-p)
    (forward-char)))

关于Emacs 插入居中的注释 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21042321/

相关文章:

emacs - 在 Emacs 中模拟迷你缓冲区输入

python - Pydoc 弄乱了 -*- 编码 : utf-8 -*-

c - 提供下面提到的 typedef 和 #define 行为差异的原因

latex - LaTeX中多行表格上的行色

python - LaTeX 与 Python 3.7 和 Matplotlib

latex - 将 jupyter 笔记本表格向左对齐

emacs - Emacs 中的全行补全?

linux - 在远程服务器上以图形模式运行 emacs

macros - SPSS 宏在多个数据文件中运行聚合命令

c++ - C++ 宏可以计算 switch 语句中的案例吗?