Skip to content

Instantly share code, notes, and snippets.

@nhoriguchi
Created November 26, 2019 16:31
Show Gist options
  • Save nhoriguchi/cf8e7e25e9b83ca1b0d544ceb49110f7 to your computer and use it in GitHub Desktop.
Save nhoriguchi/cf8e7e25e9b83ca1b0d544ceb49110f7 to your computer and use it in GitHub Desktop.

Emacs の拡張機能として pangu-spacing というライブラリを公開している人がいる。全角文字と半角文字の間に自動でスペースを入れてくれる機能で、スペースを開ける派の私には大変ありがたい拡張である。難点としては、バッファ全体に自動適用されてしまうので、例えばメールの編集をしているときなど、引用元のメールのテキストに対しても作用してしまうというのがあった。そこで指定したリージョン内だけ pangu-spacing を発動させたいということになる。

少しライブラリを いじって やって、.emacs 内に下記関数を定義すれば、指定リージョンあるいはパラグラフ内に pangu-spacing を適用することができ、かなり実用性を高めることができる。

(defun pangu-spacing-space-current-region ()
  ""
  (interactive "r")
  (pangu-spacing-modify-region (region-beginning) (region-end))
  )

(defun pangu-spacing-space-current-paragraph ()
  (interactive)
  (progn
   (setq initial-pos (point))
   (mark-paragraph -1)
   (pangu-spacing-space-current-region)
   (goto-char initial-pos)
   ))
(define-key global-map "\M-." 'pangu-spacing-space-current-paragraph)

Emacs Lisp のお作法を少し無視しているかもしれないが、まずは使えるものが手に入ったということで。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment