Emacs-用字符X填充一行直到列Y



是否有Emacs命令可以用特定字符"填充"一行,直到指定的列?基本上相当于这个问题,除了使用Emacs而不是Vim。

例如,假设我开始输入如下行:

/* -- Includes
/* -- Procedure Prototypes
/* -- Procedures 

我想要一个命令,无论光标当前在哪一列,它都会自动用短划线填充行的其余部分(最多可以指定一列)。

/* -- Includes -----------------------------------------------------
/* -- Procedure Prototypes -----------------------------------------
/* -- Procedures ---------------------------------------------------

谢谢。很抱歉,如果已经问过这个问题,我在谷歌上找不到任何东西。

以下是应该起作用的东西:

(defun fill-to-end ()
  (interactive)
  (save-excursion
    (end-of-line)
    (while (< (current-column) 80)
      (insert-char ?-))))

它将-字符追加到当前行的末尾,直到到达第80列。如果要指定字符,则应将其更改为

(defun fill-to-end (char)
  (interactive "cFill Character:")
  (save-excursion
    (end-of-line)
    (while (< (current-column) 80)
      (insert-char char))))
(defun char-fill-to-col (char column &optional start end)
  "Fill region with CHAR, up to COLUMN."
  (interactive "cFill with char: nnto column: nr")
  (let ((endm  (copy-marker end)))
    (save-excursion
      (goto-char start)
      (while (and (not (eobp))  (< (point) endm))
        (end-of-line)
        (when (< (current-column) column)
          (insert (make-string (- column (current-column)) char)))
        (forward-line 1)))))
(defun dash-fill-to-col (column &optional start end)
  "Fill region with dashes, up to COLUMN."
  (interactive "nFill with dashes up to column: nr")
  (char-fill-to-col ?- column start end))

最新更新