-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlisp.el
More file actions
206 lines (160 loc) · 6.79 KB
/
lisp.el
File metadata and controls
206 lines (160 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
;; -*-emacs-lisp-*-
;;;
;;; Lisp (Emacs Lisp, Common Lisp, slime, and Scheme) configuration
;;;
(defun syntactic-close-or-self-insert (&optional arg)
"Call `syntactic-close' and if there is no matching character,
insert the character the user typed by calling `self-insert-command'."
(interactive "P")
(unless (call-interactively 'syntactic-close)
(call-interactively 'self-insert-command nil
[(listify-key-sequence (this-command-keys))])))
(defun cinsk/register-syntactic-close-binding (map)
(define-key map [(?\))] 'syntactic-close-or-self-insert)
(define-key map [(?\])] 'syntactic-close-or-self-insert)
(define-key map [(?\})] 'syntactic-close-or-self-insert)
(define-key map [(?\>)] 'syntactic-close-or-self-insert))
(when (locate-library "syntactic-close")
;; '(lisp-interaction-mode-map emacs-lisp-mode-map lisp-mode-map)
(cinsk/register-syntactic-close-binding lisp-mode-shared-map)
(with-eval-after-load "racket-mode"
(cinsk/register-syntactic-close-binding racket-mode-map))
(with-eval-after-load "geiser-repl"
(cinsk/register-syntactic-close-binding geiser-repl-mode-map))
(with-eval-after-load "scheme"
(cinsk/register-syntactic-close-binding scheme-mode-map))
(with-eval-after-load "clojure-mode"
(cinsk/register-syntactic-close-binding clojure-mode-map)))
(with-eval-after-load "lisp-mode"
(define-key emacs-lisp-mode-map [f5] 'eval-buffer)
(define-key emacs-lisp-mode-map [(control c) ?\|] 'eval-region))
;;;
;;; Emacs Lisp Mode
;;;
(add-hook 'emacs-lisp-mode-hook
#'(lambda ()
(cinsk/visit-tags-table (path-join user-emacs-directory
"TAGS.emacs") t)))
(with-eval-after-load "lisp-mode"
(define-key emacs-lisp-mode-map [f5] 'eval-buffer)
(define-key emacs-lisp-mode-map [(control c) ?\|] 'eval-region))
;;;
;;; Common Lisp Mode -- from clisp-2.38/editors.txt
;;;
;;; It seems that Emacs already have `lisp-eval-last-sexp' that has
;;; the same feature of `
;; clisp does not work with slime package for now -- cinsk
;;(setq inferior-lisp-program "clisp -I -q -E utf-8")
;;(setq inferior-lisp-program "sbcl")
(defun lisp-macroexpand-region (start end &optional and-go)
"Macroexpand the current region in the inferior Lisp process.
Prefix argument means switch to the Lisp buffer afterwards."
(interactive "r\nP")
(comint-send-string
(inferior-lisp-proc)
(format "(macroexpand-1 (quote %s))\n"
(buffer-substring-no-properties start end)))
(if and-go (switch-to-lisp t)))
(defun lisp-macroexpand-sexp (&optional and-go)
"Macroexpand the next sexp in the inferior Lisp process.
Prefix argument means switch to the Lisp buffer afterwards."
(interactive "P")
(lisp-macroexpand-region (point) (scan-sexps (point) 1) and-go))
(with-eval-after-load "inf-lisp"
(define-key inferior-lisp-mode-map [(control ?x) (control ?m)]
'lisp-macro-expand-sexp))
(define-key lisp-mode-map [(control ?x) (control ?m)] 'lisp-macro-expand-sexp)
;;;
;;; slime
;;;
(when (locate-library "slime-autoloads")
(with-eval-after-load "slime"
(slime-setup)
;; C-c C-b slime-eval-buffer
;; C-c C-e slime-eval-last-expression
;; C-c C-r slime-eval-region
;; `M-x slime-interrupt' moved to `C-c C-B' from `C-c C-b'
(cinsk/move-key slime-mode-map [(control ?c) (control ?b)]
[(control ?c) (control ?B)])
(cinsk/move-key slime-mode-map [(control ?c) (control ?e)]
[(control meta ?\:)])
;; C-c v slime-describe-symbol
;; C-c f slime-describe
;;(define-key slime-mode-map [(control ?c) ?v] 'slime-describe-symbol)
;;(define-key slime-mode-map [(control ?c) ?f] 'slime-describe-function)
(define-key slime-mode-map [(control ?c) (control ?e)]
'slime-eval-last-expression)
(define-key slime-mode-map [(control ?c) (control ?b)]
'slime-eval-buffer))
(require 'slime-autoloads))
;; clisp does not work with slime package for now -- cinsk
;;(setq inferior-lisp-program "clisp -I -q -E utf-8")
(if (locate-file "sbcl" exec-path)
(setq inferior-lisp-program "sbcl"))
;;;
;;; quack (enhanced support for scheme-mode)
;;;
(when (locate-library "quack")
(require 'quack)
(setq quack-browse-url-browser-function 'quack-w3m-browse-url-other-window)
(setq quack-fontify-style 'emacs)
(setq quack-default-program "mzscheme"))
(defun scheme-grep-symbols-on-region ()
"Insert all global symbols into the selected buffer"
(interactive)
(let ((src (current-buffer))
(dst (get-buffer-create "*scheme-tmp*"))
(begin (region-beginning))
(end (region-end)))
(save-excursion
(set-buffer dst)
(erase-buffer)
(scheme-mode)
(insert "(provide "))
(save-excursion
(narrow-to-region begin end)
(goto-char (point-min))
(while (re-search-forward
"(define[ \t\v\n]+(?[ \t\v\n]*\\([^ )\t\v\n]*\\)" nil t)
(let ((word (match-string-no-properties 1)))
(set-buffer dst)
(insert word)
;;(indent-according-to-mode)
;;(newline)
(newline-and-indent)
(set-buffer src))))
))
(when (locate-library "eldoc")
(require 'eldoc)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode))
(when (and nil (locate-library "paredit"))
(autoload 'enable-paredit-mode "paredit"
"Turn on pseudo-structural editing of Lisp code." t)
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)
;; See http://www.emacswiki.org/emacs/ParEdit
(eldoc-add-command
'paredit-backward-delete
'paredit-close-round))
(when (locate-library "geiser")
(when (locate-library "racket-mode")
(add-hook 'racket-mode-hook #'(lambda () (geiser-mode 1)))
;; geiser-mode made .rkt file uses scheme-mode. Force to use
;; racket-mode if it is installed
(cinsk/priortize-auto-mode 'racket-mode)))
(with-eval-after-load "racket-mode"
(when (locate-library "geiser")
;; `C-c C-c' bound to `racket-run`, which is unnecessary since we
;; are going to use geiser's `geiser-mode-switch-to-repl' to
;; create the REPL. Also, I am used to use `C-c C-c' as
;; `comment-region'.
(define-key racket-mode-map [(control ?c) (control ?c)] nil)))
(with-eval-after-load "geiser-mode"
(define-key geiser-mode-map [(control ?c) ?\!] 'geiser-mode-switch-to-repl)
(cinsk/move-key geiser-mode-map [(control ?c) (control ?c)] [(control ?c) (control ?C)]))