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)
|
||||
|
||||
;; Some Elisp indentation stuff
|
||||
;; Source: https://github.com/magit/emacsql
|
||||
;; emacsql.el line 394
|
||||
(defun my/lisp-inside-plist-p ()
|
||||
"Return t if point is inside a plist."
|
||||
(defun my/lisp-inside-funcall-like-p ()
|
||||
"Return non-nil if the point in within a list beginning with a symbol.
|
||||
That is, (abc) is non-nil and (\"abc\") is nil. Actually, return the position
|
||||
of the opening paren of the current list."
|
||||
(save-excursion
|
||||
(let ((start (point)))
|
||||
(beginning-of-defun)
|
||||
(when-let* ((sexp (nth 1 (parse-partial-sexp (point) start))))
|
||||
(when-let* ((sexp (nth 1 (syntax-ppss))))
|
||||
(when (eql (char-after 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)
|
||||
"This function is meant to advise `calculate-lisp-indent'.
|
||||
It calls OLDFUN with ARGS in such an environment as to prevent the default
|
||||
indentation of plists."
|
||||
(if (and (eq major-mode 'emacs-lisp-mode)
|
||||
(save-excursion
|
||||
(beginning-of-line)
|
||||
(my/lisp-inside-plist-p)))
|
||||
(let ((lisp-indent-offset 1))
|
||||
(apply oldfun args))
|
||||
(apply oldfun args)))
|
||||
(defun my/-calculate-indent-better-lists "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
|
||||
first expression on that line is lined up with the first symbol in the list
|
||||
above, keep the indention. Otherwise, indent as with ARGS applied to OLDFUN."
|
||||
(oldfun &rest args)
|
||||
(let ((init-prev-bol (pos-bol 0)))
|
||||
(or (save-excursion
|
||||
(when-let* (;; if we on the first line of the buffer, do nothing
|
||||
((not (eql (pos-bol) (point-min))))
|
||||
(sexp (my/lisp-inside-funcall-like-p)))
|
||||
(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
|
||||
'my/-calculate-indent-fix-plists)
|
||||
#'my/-calculate-indent-better-lists)
|
||||
|
||||
(defvar my/max-lisp-noindent-comment-search-lines 30
|
||||
"Max lines to search for the noindent comment.")
|
||||
@@ -2224,7 +2240,7 @@ line in the block and manually deal with indentation."
|
||||
(apply oldfun args)))
|
||||
|
||||
(advice-add 'calculate-lisp-indent :around
|
||||
'my/-calculate-lisp-indent-noindent-comment)
|
||||
#'my/-calculate-lisp-indent-noindent-comment)
|
||||
|
||||
;; common lisp
|
||||
(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))
|
||||
(file (bookmark-get-filename record)))
|
||||
(format "%s => %s"
|
||||
(propertize name 'face '(:foreground "deep sky blue"
|
||||
(propertize name 'face
|
||||
'(:foreground "deep sky blue"
|
||||
:weight bold))
|
||||
(if (file-directory-p file)
|
||||
(file-name-as-directory file)
|
||||
|
||||
Reference in New Issue
Block a user