Skip to content

Commit 7c3a604

Browse files
committed
added a few keywords, changed indent on ([] ...) for defn forms, added some indent hints
1 parent c08f802 commit 7c3a604

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

clojure-mode/clojure-mode.el

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ if that value is non-nil."
152152
nil
153153
(font-lock-mark-block-function . mark-defun)
154154
(font-lock-syntactic-face-function . lisp-font-lock-syntactic-face-function)))
155+
155156
(run-mode-hooks 'clojure-mode-hook))
156157

157158
(defun clojure-font-lock-def-at-point (point)
@@ -238,7 +239,7 @@ elements of a def* forms."
238239
;; Function declarations.
239240
"\\(n-?\\|multi\\|macro\\|method\\|"
240241
;; Variable declarations.
241-
""
242+
"struct\\|"
242243
"\\)\\)\\>"
243244
;; Any whitespace
244245
"[ \r\n\t]*"
@@ -252,11 +253,12 @@ elements of a def* forms."
252253
(,(concat
253254
"(\\(?:clojure/\\)?"
254255
(regexp-opt
255-
'("cond" "for" "if" "loop" "let" "recur" "do" "binding" "with-meta" "when"
256-
"when-not" "delay" "lazy-cons" "." ".." "->" "and" "or" "locking"
256+
'("cond" "for" "loop" "let" "recur" "do" "binding" "with-meta"
257+
"when" "when-not" "when-let" "when-first" "if" "if-let"
258+
"delay" "lazy-cons" "." ".." "->" "and" "or" "locking"
257259
"sync" "doseq" "dotimes" "import" "unimport" "in-ns" "refer"
258260
"implement" "proxy" "time" "try" "catch" "finally"
259-
"doto" "with-open" "with-local-vars" ) t)
261+
"doto" "with-open" "with-local-vars" "struct-map" ) t)
260262
"\\>")
261263
. 1)
262264
;; (fn name? args ...)
@@ -327,7 +329,9 @@ This function also returns nil meaning don't specify the indentation."
327329
;; thing on that line has to be complete sexp since we are
328330
;; inside the innermost containing sexp.
329331
(backward-prefix-chars)
330-
(current-column))
332+
(if (eq (char-after (point)) ?\[)
333+
(+ (current-column) 2) ;; this is probably inside a defn
334+
(current-column)))
331335
(let ((function (buffer-substring (point)
332336
(progn (forward-sexp 1) (point))))
333337
(open-paren (elt state 1))
@@ -341,6 +345,7 @@ This function also returns nil meaning don't specify the indentation."
341345
(> (length function) 3)
342346
(string-match "\\`def" function)))
343347
(lisp-indent-defform state indent-point))
348+
344349
((integerp method)
345350
(lisp-indent-specform method state
346351
indent-point normal-indent))
@@ -393,6 +398,22 @@ check for contextual indenting."
393398
(error (setq depth clojure-max-backtracking)))))
394399
indent))
395400

401+
402+
;; (defun clojure-indent-defn (indent-point state)
403+
;; "Indent by 2 if after a [] clause that's at the beginning of a
404+
;; line"
405+
;; (if (not (eq (char-after (elt state 2)) ?\[))
406+
;; (lisp-indent-defform state indent-point)
407+
;; (goto-char (elt state 2))
408+
;; (beginning-of-line)
409+
;; (skip-syntax-forward " ")
410+
;; (if (= (point) (elt state 2))
411+
;; (+ (current-column) 2)
412+
;; (lisp-indent-defform state indent-point))))
413+
414+
;; (put 'defn 'clojure-indent-function 'clojure-indent-defn)
415+
;; (put 'defmacro 'clojure-indent-function 'clojure-indent-defn)
416+
396417
;; clojure backtracking indent is experimental and the format for these
397418
;; entries are subject to change
398419
(put 'implement 'clojure-backtracking-indent '(4 (2)))
@@ -406,6 +427,9 @@ check for contextual indenting."
406427
(put 'if 'clojure-indent-function 1)
407428
(put 'let 'clojure-indent-function 1)
408429
(put 'loop 'clojure-indent-function 1)
430+
(put 'struct-map 'clojure-indent-function 1)
431+
(put 'assoc 'clojure-indent-function 1)
432+
(put 'fn 'clojure-indent-function 2)
409433

410434
;; macro indent (auto generated)
411435
(put 'binding 'clojure-indent-function 1)
@@ -417,11 +441,14 @@ check for contextual indenting."
417441
(put 'implement 'clojure-indent-function 1)
418442
(put 'lazy-cons 'clojure-indent-function 1)
419443
(put 'let 'clojure-indent-function 1)
444+
(put 'when-let 'clojure-indent-function 2)
445+
(put 'if-let 'clojure-indent-function 2)
420446
(put 'locking 'clojure-indent-function 1)
421447
(put 'proxy 'clojure-indent-function 2)
422448
(put 'sync 'clojure-indent-function 1)
423449
(put 'when 'clojure-indent-function 1)
424450
(put 'when-first 'clojure-indent-function 2)
451+
(put 'when-let 'clojure-indent-function 2)
425452
(put 'when-not 'clojure-indent-function 1)
426453
(put 'with-local-vars 'clojure-indent-function 1)
427454
(put 'with-open 'clojure-indent-function 2)

0 commit comments

Comments
 (0)