开启新的一行
在emacs中可以用C-j来新建一行但是必须先执行C-e引动到句子末尾才行,但是写程序时非常不方便。所以我们做了下面更改,可以不移动到句末,在句子中间就新建一行。
;;重新定义C-j快捷键
(defun my-new-line-and-indent (arg)
(interactive "^p")
(or arg (setq arg 1))
(let (done)
(while (not done)
(let ((newpos
(save-excursion
(let ((goal-column 0)
(line-move-visual nil))
(and (line-move arg t)
(not (bobp))
(progn
(while (and (not (bobp)) (invisible-p (1- (point))))
(goto-char (previous-single-char-property-change
(point) 'invisible)))
(backward-char 1)))
(point)))))
(goto-char newpos)
(if (and (> (point) newpos)
(eq (preceding-char) ?\n))
(backward-char 1)
(if (and (> (point) newpos) (not (eobp))
(not (eq (following-char) ?\n)))
;; If we skipped something intangible and now we're not
;; really at eol, keep going.
(setq arg 1)
(setq done t))))))
(newline-and-indent))
(global-set-key (kbd "C-j") 'my-new-line-and-indent)