Last active
August 22, 2019 16:05
-
-
Save yonta/db4a31c10dcc862b78ba8b9ded4f4076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; (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