Emacs 簡単なコマンド

http://cmdnote.net/search?q=tag%3Aemacs に移転します。

インデントつき open-line

open-line した後にインデントさせるコマンドを作る。

(defun open-line-and-indent (&optional n)
  "Open line and indent."
  (interactive "p")
  (open-line n)
  (indent-according-to-mode))

ポイントの近くの行を複製する

duplicate-previous-line
ポイントの n 行前の行から n 行複製する
duplicate-next-line
ポイントの次の行から n 行複製する
duplicate-current-line
ポイントのある行から n 行複製する

(defun duplicate-line-near-current-point (start-line &optional copy-num) (save-excursion (forward-line start-line) (let* ((num (or copy-num 1)) (start-pt (point)) (end-pt (save-excursion (forward-line num) (point)))) (when (= start-line 0) (forward-line num)) (insert (buffer-substring start-pt end-pt)))))

(defun duplicate-previous-line (n) “Duplicate previous N lines.” (interactive “p”) (duplicate-line-near-current-point (- n) n))

(defun duplicate-next-line (n) “Duplicate next N lines.” (interactive “p”) (duplicate-line-near-current-point 1 n))

(defun duplicate-current-line (n) “Duplicate current line.” (interactive “p”) (duplicate-line-near-current-point 0 n))

カレントディレクトリ(またはホームディレクトリ)からの相対パスを挿入する

ファイルの相対パスを挿入する。 from-home が真であるならホームディレクトリからの相対パスを挿入する。

(defun insert-relative-path (&optional from-home)
  "Insert relative path from file of current buffer.
If FROM-HOME is true, returned path starts from \"~/\"."
  (interactive "P")
  (if from-home (insert (read-file-name "Path: " "~/"))
    (insert (file-relative-name (read-file-name "Path: " default-directory) default-directory))))

カーソル位置の関数を kill-ring にコピーする

カーソル位置にある関数の名前を kill-ring にコピーする。 which-func を使う。

(require 'which-func)

(defun copy-current-function-name ()
  (interactive)
  (let ((func (condition-case nil (which-function))))
    (if func
	(progn
	  (kill-new func)
	  (message "Copy %s" func))
      (message "Can not find name of function"))))

Tags of current page