Skip to content

Commit

Permalink
Simplify indent
Browse files Browse the repository at this point in the history
Replace lisp-mode `calculate-lisp-indent` with our own, much simpler
function `racket--calculate-indent'.

Fixes #243.
Fixes #262.
  • Loading branch information
Greg Hendershott committed Jun 2, 2017
1 parent 4cfb2eb commit beeda04
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 259 deletions.
3 changes: 3 additions & 0 deletions example/example.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

;;; NOTE: After changing this file you will need to M-x faceup-write-file
;;; to regenerate the .faceup test comparison file.
;;;
;;; NOTE: You may need to disable certain features -- for example
;;; global-paren-face-mode -- during the M-x faceup-write-file.

#lang racket

Expand Down
3 changes: 3 additions & 0 deletions example/example.rkt.faceup
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
»
«m:;;; »«x:NOTE: After changing this file you will need to M-x faceup-write-file
»«m:;;; »«x:to regenerate the .faceup test comparison file.
»«m:;;;»«x:
»«m:;;; »«x:NOTE: You may need to disable certain features -- for example
»«m:;;; »«x:global-paren-face-mode -- during the M-x faceup-write-file.
»
«k:#lang» «v:racket»

Expand Down
23 changes: 19 additions & 4 deletions example/indent.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

;;; NOTE: After changing this file you will need to M-x faceup-write-file
;;; to regenerate the .faceup test comparison file.
;;;
;;; NOTE: You may need to disable certain features -- for example
;;; global-paren-face-mode -- during the M-x faceup-write-file.

;;; Quoted list

Expand Down Expand Up @@ -221,10 +224,10 @@

;; for/fold typed, type on same line
(for/fold : T
([a 0]
[b 0])
([x 0]
[y 0])
([a 0]
[b 0])
([x 0]
[y 0])
#t)

;; for/fold typed, type on different line
Expand Down Expand Up @@ -308,3 +311,15 @@
3)
2
3)

;; Bug #243
(cond [x y
z]
[(= a x) y
z])

;; Bug #262
(define-metafunction λL
∪ : (x ...) ... -> (x ...)
[(∪ any_ls ...)
,(apply append (term (any_ls ...)))])
23 changes: 19 additions & 4 deletions example/indent.rkt.faceup
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
»
«m:;;; »«x:NOTE: After changing this file you will need to M-x faceup-write-file
»«m:;;; »«x:to regenerate the .faceup test comparison file.
»«m:;;;»«x:
»«m:;;; »«x:NOTE: You may need to disable certain features -- for example
»«m:;;; »«x:global-paren-face-mode -- during the M-x faceup-write-file.
»
«m:;;; »«x:Quoted list
»
Expand Down Expand Up @@ -221,10 +224,10 @@

«m:;; »«x:for/fold typed, type on same line
»«:racket-paren-face:(»«k:for/fold» «b::» T
«:racket-paren-face:([»a «:racket-selfeval-face:0»«:racket-paren-face:]»
«:racket-paren-face:[»b «:racket-selfeval-face:0»«:racket-paren-face:])»
«:racket-paren-face:([»x «:racket-selfeval-face:0»«:racket-paren-face:]»
«:racket-paren-face:[»y «:racket-selfeval-face:0»«:racket-paren-face:])»
«:racket-paren-face:([»a «:racket-selfeval-face:0»«:racket-paren-face:]»
«:racket-paren-face:[»b «:racket-selfeval-face:0»«:racket-paren-face:])»
«:racket-paren-face:([»x «:racket-selfeval-face:0»«:racket-paren-face:]»
«:racket-paren-face:[»y «:racket-selfeval-face:0»«:racket-paren-face:])»
«:racket-selfeval-face:#t»«:racket-paren-face:)»

«m:;; »«x:for/fold typed, type on different line
Expand Down Expand Up @@ -308,3 +311,15 @@
3)»
«:racket-selfeval-face:2»
«:racket-selfeval-face:3»«:racket-paren-face:)»

«m:;; »«x:Bug #243
»«:racket-paren-face:(»«k:cond» «:racket-paren-face:[»x y
z«:racket-paren-face:]»
«:racket-paren-face:[(»«b:=» a x«:racket-paren-face:)» y
z«:racket-paren-face:])»

«m:;; »«x:Bug #262
»«:racket-paren-face:(»define-metafunction «v:λL
» ∪ «b::» «:racket-paren-face:(»x «k:...»«:racket-paren-face:)» «k:...» «b:->» «:racket-paren-face:(»x «k:...»«:racket-paren-face:)»
«:racket-paren-face:[(»∪ any_ls «k:...»«:racket-paren-face:)»
,«:racket-paren-face:(»«k:apply» «b:append» «:racket-paren-face:(»term «:racket-paren-face:(»any_ls «k:...»«:racket-paren-face:)))])»
1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ compile: clean \
racket-keywords-and-builtins.elc \
racket-make-doc.elc \
racket-mode.elc \
racket-ppss.elc \
racket-profile.elc \
racket-repl.elc \
racket-tests.elc \
Expand Down
9 changes: 5 additions & 4 deletions racket-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,20 @@ a list of all modes in which Racket is edited."
(setq-local parse-sexp-ignore-comments t)
(setq-local comment-column 40)
;; -----------------------------------------------------------------
;; Indent
(setq-local indent-line-function #'racket-indent-line)
(racket--set-indentation)
(setq-local indent-tabs-mode nil)
;; -----------------------------------------------------------------
;;; Misc
(setq-local local-abbrev-table racket-mode-abbrev-table)
(setq-local paragraph-start (concat "$\\|" page-delimiter))
(setq-local paragraph-separate paragraph-start)
(setq-local paragraph-ignore-fill-prefix t)
(setq-local fill-paragraph-function #'lisp-fill-paragraph)
(setq-local adaptive-fill-mode nil)
(setq-local indent-line-function #'racket-indent-line)
(setq-local parse-sexp-ignore-comments t)
(setq-local outline-regexp ";;; \\|(....")
(setq-local lisp-indent-function #'racket-indent-function)
(racket--set-indentation)
(setq-local indent-tabs-mode nil)
(setq-local completion-at-point-functions (list #'racket-complete-at-point))
(setq-local eldoc-documentation-function nil)
(setq-local beginning-of-defun-function #'racket--beginning-of-defun-function))
Expand Down
2 changes: 1 addition & 1 deletion racket-custom.el
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ This is safe to set as a file-local variable."
:group 'racket-other)

(defcustom racket-indent-sequence-depth 0
"To what depth should `racket--align-sequence-to-head' search.
"To what depth should `racket-indent-line' search.
This affects the indentation of forms like `` '()` `() #() `` --
and `{}` if `racket-indent-curly-as-sequence' is t -- but not
`` #'() #`() ,() ,@() ``. A zero value disables, giving the
Expand Down
Loading

0 comments on commit beeda04

Please sign in to comment.