Emacs插入居中注释块

 极神bd韵 发布于 2023-02-04 17:06

我想为emacs创建一个宏,该宏将插入带有一些居中文本的乳胶注释块,例如:

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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%           Comment 2 Commenttext 3           %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

这可能emacs-lisp吗?

1 个回答
  • 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)))
    

    2023-02-04 17:12 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有