Update elisp indent rules
This commit is contained in:
61
init.el
61
init.el
@@ -2158,31 +2158,47 @@ This is :around advice, so OLDFUN is the real function
|
|||||||
(use-package yaml-mode)
|
(use-package yaml-mode)
|
||||||
|
|
||||||
;; Some Elisp indentation stuff
|
;; Some Elisp indentation stuff
|
||||||
;; Source: https://github.com/magit/emacsql
|
(defun my/lisp-inside-funcall-like-p ()
|
||||||
;; emacsql.el line 394
|
"Return non-nil if the point in within a list beginning with a symbol.
|
||||||
(defun my/lisp-inside-plist-p ()
|
That is, (abc) is non-nil and (\"abc\") is nil. Actually, return the position
|
||||||
"Return t if point is inside a plist."
|
of the opening paren of the current list."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((start (point)))
|
(when-let* ((sexp (nth 1 (syntax-ppss))))
|
||||||
(beginning-of-defun)
|
(when (eql (char-after sexp) ?\()
|
||||||
(when-let* ((sexp (nth 1 (parse-partial-sexp (point) start))))
|
|
||||||
(goto-char sexp)
|
(goto-char sexp)
|
||||||
(looking-at (rx "(" (* (syntax whitespace)) ":"))))))
|
(ignore-errors
|
||||||
|
(forward-char)
|
||||||
|
(let ((res (let ((obarray (obarray-make)))
|
||||||
|
(read (current-buffer)))))
|
||||||
|
(and (symbolp res) sexp)))))))
|
||||||
|
|
||||||
(defun my/-calculate-indent-fix-plists (oldfun &rest args)
|
(defun my/-calculate-indent-better-lists "This function is meant to advise `calculate-lisp-indent'.
|
||||||
"This function is meant to advise `calculate-lisp-indent'.
|
If the point is on the second line of a list that begins with a symbol and the
|
||||||
It calls OLDFUN with ARGS in such an environment as to prevent the default
|
first expression on that line is lined up with the first symbol in the list
|
||||||
indentation of plists."
|
above, keep the indention. Otherwise, indent as with ARGS applied to OLDFUN."
|
||||||
(if (and (eq major-mode 'emacs-lisp-mode)
|
(oldfun &rest args)
|
||||||
(save-excursion
|
(let ((init-prev-bol (pos-bol 0)))
|
||||||
(beginning-of-line)
|
(or (save-excursion
|
||||||
(my/lisp-inside-plist-p)))
|
(when-let* (;; if we on the first line of the buffer, do nothing
|
||||||
(let ((lisp-indent-offset 1))
|
((not (eql (pos-bol) (point-min))))
|
||||||
(apply oldfun args))
|
(sexp (my/lisp-inside-funcall-like-p)))
|
||||||
(apply oldfun args)))
|
(goto-char sexp)
|
||||||
|
(forward-char)
|
||||||
|
(skip-syntax-forward " ")
|
||||||
|
(while (eolp)
|
||||||
|
(forward-line)
|
||||||
|
(skip-syntax-forward " "))
|
||||||
|
(when (eql (pos-bol) init-prev-bol)
|
||||||
|
(let ((upper-offset (- (point) (pos-bol))))
|
||||||
|
(forward-line)
|
||||||
|
(let ((lower-offset (skip-syntax-forward " ")))
|
||||||
|
(when (and (eql upper-offset lower-offset)
|
||||||
|
(not (eql (char-after) ?\))))
|
||||||
|
upper-offset))))))
|
||||||
|
(apply oldfun args))))
|
||||||
|
|
||||||
(advice-add 'calculate-lisp-indent :around
|
(advice-add 'calculate-lisp-indent :around
|
||||||
'my/-calculate-indent-fix-plists)
|
#'my/-calculate-indent-better-lists)
|
||||||
|
|
||||||
(defvar my/max-lisp-noindent-comment-search-lines 30
|
(defvar my/max-lisp-noindent-comment-search-lines 30
|
||||||
"Max lines to search for the noindent comment.")
|
"Max lines to search for the noindent comment.")
|
||||||
@@ -2224,7 +2240,7 @@ line in the block and manually deal with indentation."
|
|||||||
(apply oldfun args)))
|
(apply oldfun args)))
|
||||||
|
|
||||||
(advice-add 'calculate-lisp-indent :around
|
(advice-add 'calculate-lisp-indent :around
|
||||||
'my/-calculate-lisp-indent-noindent-comment)
|
#'my/-calculate-lisp-indent-noindent-comment)
|
||||||
|
|
||||||
;; common lisp
|
;; common lisp
|
||||||
(use-package lisp-mode
|
(use-package lisp-mode
|
||||||
@@ -2886,7 +2902,8 @@ If no name is given, list all bookmarks instead."
|
|||||||
(let ((name (bookmark-name-from-full-record record))
|
(let ((name (bookmark-name-from-full-record record))
|
||||||
(file (bookmark-get-filename record)))
|
(file (bookmark-get-filename record)))
|
||||||
(format "%s => %s"
|
(format "%s => %s"
|
||||||
(propertize name 'face '(:foreground "deep sky blue"
|
(propertize name 'face
|
||||||
|
'(:foreground "deep sky blue"
|
||||||
:weight bold))
|
:weight bold))
|
||||||
(if (file-directory-p file)
|
(if (file-directory-p file)
|
||||||
(file-name-as-directory file)
|
(file-name-as-directory file)
|
||||||
|
|||||||
Reference in New Issue
Block a user