Emacs插入中心注释块 [英] Emacs insert centered comment block

查看:185
本文介绍了Emacs插入中心注释块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我想为emacs创建一个宏,该宏将插入一个带有一些中心文本的胶乳注释块, %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%评论1 %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%评论2 Commenttext 3 %%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% b $ b

这是否可能在 emacs-lisp ? / p>

解决方案

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

 这是一个注释

当您调用 Mx评论框时,文本将转换为:

  ;;;;;;;;;;;;;;;;;;;;;;; 
;;这是一个评论
;;;;;;;;;;;;;;;;;;;;;;;;

如果区域不活动,我使用一个修改版本将注释框放在当前行周围,然后再退出评论。它也会暂时减少填充列,因此注释框不会超过最长行:

 (defun ty-box 
(交互式* r \\\
p)
(当(not(region-active-p))
(setq beg(point-在
(setq end(point-at-eol)))
(let((fill-column( - fill-column 6)))
(fill-region beg结束))
(comment-box beg end arg)
(ty-move-point-forward-out-of-comment))

(defun ty-point-is -in-comment-p()
t如果点在注释行或注释行的开头,否则为
(或(nth 4(syntax-ppss))
(查找^ \\\s * \\s<)))

(defun ty-move-point-forward-out-of-comment()
向前移动点,直到不再有注释
(while(ty-point-is-in-comment-p)
(forward-char)))


I would like to create a macro for emacs that will insert a latex comment block with some centerd text like:

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


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

Is this possible in emacs-lisp?

解决方案

Emacs comes with the command comment-box for this purpose. It produces centered comment boxes, although the width of the box varies depending on the content. E.g., with the region set around the following line:

This is a comment

when you call M-x comment-box the text is transformed to:

;;;;;;;;;;;;;;;;;;;;;;;
;; This is a comment ;;
;;;;;;;;;;;;;;;;;;;;;;;

I use a modifed version that places the comment box around the current line if the region isn't active, and then steps out of the comment afterwards. It also temporarily reduces the fill-column, so the comment box is not wider than your longest line:

(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插入中心注释块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆