2015-04-03 51 views
2

是否有Emacs命令可以用特定字符「填充」一行直到指定列?基本上相當於this question,除了用Emacs代替Vim。Emacs - 用字符X填充一行直到Y列

舉個例子,說我開始進入看起來像這樣的臺詞:與

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

我想,在該行的其餘部分將自動填充(最多我可以指定一列)的命令破折號,不管光標當前在哪一列。

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

謝謝。對不起,如果這已被問到,我找不到任何與谷歌。

回答

2

這裏的東西應該工作:

(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)))) 
1
(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)) 
相關問題