Guest User

[Emacs] リージョン非活性時の M-; で `comment-or-uncomment-region' 呼び出し

a guest
Nov 15th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.02 KB | None | 0 0
  1. ;; リージョンが非活性時の M-; で `comment-indent' ではなく
  2. ;; `comment-or-uncomment-region' を実行する。
  3. (global-set-key (kbd "M-;")
  4.                 (lambda (arg)
  5.                   (interactive "*P")
  6.                   (let ((bol (line-beginning-position))
  7.                         (eol (line-end-position)))
  8.                     (if (or
  9.                          ;; リージョンが活性
  10.                          (use-region-p)
  11.                          ;; 空行
  12.                          (string-match (buffer-substring-no-properties bol eol)
  13.                                        "\\`\\s-*\\'")
  14.                          ;; 前置引数(C-u)あり
  15.                          arg)
  16.                         (if (called-interactively-p)
  17.                             (call-interactively #'comment-dwim)
  18.                           (comment-dwim arg))
  19.                       ;; 上記以外の場合は現在行をコメント化 or コメント解除
  20.                       (comment-or-uncomment-region bol eol)))))
Add Comment
Please, Sign In to add comment