gpt4 book ai didi

Emacs 插入居中的注释 block

转载 作者:行者123 更新时间:2023-12-03 20:18:27 25 4
gpt4 key购买 nike

我想为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com