mirror of
https://github.com/vale981/boon
synced 2025-03-05 09:31:43 -05:00
improve space fixing
This commit is contained in:
parent
de711094a6
commit
129dea6431
1 changed files with 13 additions and 12 deletions
25
boon-main.el
25
boon-main.el
|
@ -91,21 +91,22 @@ When repeated, fix the spacing if necessary."
|
|||
|
||||
(defun boon-need-space ()
|
||||
"Is it necessary to insert a space here to separate words or expressions?"
|
||||
(and (not (or (eolp) (looking-at "\\s-")))
|
||||
(not (or (bolp) (looking-back "\\s-")))
|
||||
(or (and (looking-back "\\sw\\|\\s_") (looking-at "\\sw\\|\\s_"))
|
||||
;; this isn't quite ideal for haskell mode, because special
|
||||
;; characters are defined as punctuations, but there should
|
||||
;; be spaces between operators and identifiers
|
||||
(and (looking-back "\\s)") (not (looking-at "\\s)")))
|
||||
(and (not (looking-back "\\s(")) (looking-at "\\s(")))))
|
||||
(and (not (or (eolp) (looking-at "\\s-") (looking-at "\\s)")))
|
||||
(not (or (bolp) (looking-back "\\s-") (looking-back "\\s(")))
|
||||
(or (and (looking-back "\\sw\\|\\s_\\|\\s.\\|\\s)") (looking-at "\\sw\\|\\s_\\|\\s(")))))
|
||||
|
||||
(defun boon-fix-a-space ()
|
||||
"Fix the text to have exactly one space at the point.
|
||||
"Fix the text to have the right amout of spacing at the point.
|
||||
Return nil if no changes are made, t otherwise."
|
||||
(cond ((and (looking-at " ") (looking-back " "))
|
||||
(delete-char 1)
|
||||
t)
|
||||
(interactive)
|
||||
(cond ((looking-at " ")
|
||||
(when (or (bolp) (looking-back "\\s-\\|\\s("))
|
||||
(delete-char 1)
|
||||
t))
|
||||
((looking-back " ")
|
||||
(when (or (eolp) (looking-at "\\s-\\|\\s)\\|\\s."))
|
||||
(delete-char -1)
|
||||
t))
|
||||
((boon-need-space)
|
||||
(insert " ")
|
||||
t)
|
||||
|
|
Loading…
Add table
Reference in a new issue