Skip to content

Instantly share code, notes, and snippets.

@yonta
Last active August 22, 2019 16:05
Show Gist options
  • Save yonta/db4a31c10dcc862b78ba8b9ded4f4076 to your computer and use it in GitHub Desktop.
Save yonta/db4a31c10dcc862b78ba8b9ded4f4076 to your computer and use it in GitHub Desktop.
;; (setq lexical-binding nil)
;;; 任意のregionを使う関数を、選択regionがないときは現在行を与えるようにする
(defun call-with-region-or-line (func)
""
(lambda () (interactive)
(if (region-active-p) (call-interactively func)
(let ((begin (line-beginning-position))
(end (1+ (line-end-position))))
(funcall func begin end)))))
;;; こんな風にまとめたかったができなかった
;;; lexical-bindingをオンにしないと、上関数でfuncが見つからずエラーになる
(bind-key "C-c C-r" (call-with-region-or-line #'sml-prog-proc-send-region)
sml-mode-map)
(bind-key "C-c C-r" (call-with-region-or-line #'eval-region) emacs-lisp-mode-map)
;;; これならできるけど、ちょっとめんどう
(defun call-with-region-or-line (func)
""
(if (region-active-p) (call-interactively func)
(let ((begin (line-beginning-position))
(end (1+ (line-end-position))))
(funcall func begin end))))
(bind-key "C-c C-r"
(lambda () (interactive) ;; 毎回これを書く必要がある
(call-with-region-or-line #'sml-prog-proc-send-region))
sml-mode-map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment