代码之家  ›  专栏  ›  技术社区  ›  JS.

Emacs重复到给定的列?

  •  0
  • JS.  · 技术社区  · 11 年前

    在代码中添加除法器时,我可以使用

    C-<N> =

    其中N是要插入的等号的数量。

    是否有类似的快速命令可以重复插入一个字符直到给定的列号?所以我可以执行

    <magic command>-<N> =

    并得到从当前光标位置到N列的一行等号?

    1 回复  |  直到 11 年前
        1
  •  4
  •   Steve Vinoski    11 年前

    我不知道有什么内置功能可以做到这一点,但您可以将下面的函数绑定到您选择的键序列:

    (defun repeat-char-to-column (column character)
      "Insert copies of CHARACTER on the current line until column COLUMN.
    Interactively, prompt for COLUMN and CHARACTER. If the current column is
    equal to or greater than COLUMN, do nothing."
      (interactive "nRepeat to column: \ncCharacter to repeat: \n")
      (let ((cur (current-column)))
        (if (< cur column)
          (insert (make-string (- column cur) character)))))