|
3 | 3 | (git-commit-mode
|
4 | 4 | (git-commit-major-mode . git-commit-elisp-text-mode))
|
5 | 5 | (emacs-lisp-mode
|
6 |
| - (eval . (progn |
7 |
| - (let ((dirloc-lsp-defun-regexp |
8 |
| - (concat |
9 |
| - (concat "^\\s-*(" |
10 |
| - "lsp-defun" |
11 |
| - "\\s-+\\(") |
12 |
| - (or (bound-and-true-p lisp-mode-symbol-regexp) |
13 |
| - "\\(?:\\sw\\|\\s_\\|\\\\.\\)+") |
14 |
| - "\\)"))) |
15 |
| - (add-to-list 'imenu-generic-expression |
16 |
| - (list "Functions" dirloc-lsp-defun-regexp 1))) |
17 |
| - |
18 |
| - (defvar lsp--override-calculate-lisp-indent? |
19 |
| - nil |
20 |
| - "Whether to override `lisp-indent-function' with |
21 |
| - the updated `calculate-lisp-indent' definition from |
22 |
| - Emacs 28.") |
23 |
| - |
24 |
| - ;; from Emacs 28 |
25 |
| - |
26 |
| - (defun wrap-calculate-lisp-indent (func &optional parse-start) |
27 |
| - "Return appropriate indentation for current line as Lisp code. |
28 |
| -In usual case returns an integer: the column to indent to. |
29 |
| -If the value is nil, that means don't change the indentation |
30 |
| -because the line starts inside a string. |
31 |
| -
|
32 |
| -PARSE-START may be a buffer position to start parsing from, or a |
33 |
| -parse state as returned by calling `parse-partial-sexp' up to the |
34 |
| -beginning of the current line. |
35 |
| -
|
36 |
| -The value can also be a list of the form (COLUMN CONTAINING-SEXP-START). |
37 |
| -This means that following lines at the same level of indentation |
38 |
| -should not necessarily be indented the same as this line. |
39 |
| -Then COLUMN is the column to indent to, and CONTAINING-SEXP-START |
40 |
| -is the buffer position of the start of the containing expression." |
41 |
| - (if (not lsp--override-calculate-lisp-indent?) |
42 |
| - (funcall func parse-start) |
43 |
| - (save-excursion |
44 |
| - (beginning-of-line) |
45 |
| - (let ((indent-point (point)) |
46 |
| - state |
47 |
| - ;; setting this to a number inhibits calling hook |
48 |
| - (desired-indent nil) |
49 |
| - (retry t) |
50 |
| - whitespace-after-open-paren |
51 |
| - calculate-lisp-indent-last-sexp containing-sexp) |
52 |
| - (cond ((or (markerp parse-start) (integerp parse-start)) |
53 |
| - (goto-char parse-start)) |
54 |
| - ((null parse-start) (beginning-of-defun)) |
55 |
| - (t (setq state parse-start))) |
56 |
| - (unless state |
57 |
| - ;; Find outermost containing sexp |
58 |
| - (while (< (point) indent-point) |
59 |
| - (setq state (parse-partial-sexp (point) indent-point 0)))) |
60 |
| - ;; Find innermost containing sexp |
61 |
| - (while (and retry |
62 |
| - state |
63 |
| - (> (elt state 0) 0)) |
64 |
| - (setq retry nil) |
65 |
| - (setq calculate-lisp-indent-last-sexp (elt state 2)) |
66 |
| - (setq containing-sexp (elt state 1)) |
67 |
| - ;; Position following last unclosed open. |
68 |
| - (goto-char (1+ containing-sexp)) |
69 |
| - ;; Is there a complete sexp since then? |
70 |
| - (if (and calculate-lisp-indent-last-sexp |
71 |
| - (> calculate-lisp-indent-last-sexp (point))) |
72 |
| - ;; Yes, but is there a containing sexp after that? |
73 |
| - (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp |
74 |
| - indent-point 0))) |
75 |
| - (if (setq retry (car (cdr peek))) (setq state peek))))) |
76 |
| - (if retry |
77 |
| - nil |
78 |
| - ;; Innermost containing sexp found |
79 |
| - (goto-char (1+ containing-sexp)) |
80 |
| - (setq whitespace-after-open-paren (looking-at (rx whitespace))) |
81 |
| - (if (not calculate-lisp-indent-last-sexp) |
82 |
| - ;; indent-point immediately follows open paren. |
83 |
| - ;; Don't call hook. |
84 |
| - (setq desired-indent (current-column)) |
85 |
| - ;; Find the start of first element of containing sexp. |
86 |
| - (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
87 |
| - (cond ((looking-at "\\s(") |
88 |
| - ;; First element of containing sexp is a list. |
89 |
| - ;; Indent under that list. |
90 |
| - ) |
91 |
| - ((> (save-excursion (forward-line 1) (point)) |
92 |
| - calculate-lisp-indent-last-sexp) |
93 |
| - ;; This is the first line to start within the containing sexp. |
94 |
| - ;; It's almost certainly a function call. |
95 |
| - (if (or (= (point) calculate-lisp-indent-last-sexp) |
96 |
| - whitespace-after-open-paren) |
97 |
| - ;; Containing sexp has nothing before this line |
98 |
| - ;; except the first element, or the first element is |
99 |
| - ;; preceded by whitespace. Indent under that element. |
100 |
| - nil |
101 |
| - ;; Skip the first element, find start of second (the first |
102 |
| - ;; argument of the function call) and indent under. |
103 |
| - (progn (forward-sexp 1) |
104 |
| - (parse-partial-sexp (point) |
105 |
| - calculate-lisp-indent-last-sexp |
106 |
| - 0 t))) |
107 |
| - (backward-prefix-chars)) |
108 |
| - (t |
109 |
| - ;; Indent beneath first sexp on same line as |
110 |
| - ;; `calculate-lisp-indent-last-sexp'. Again, it's |
111 |
| - ;; almost certainly a function call. |
112 |
| - (goto-char calculate-lisp-indent-last-sexp) |
113 |
| - (beginning-of-line) |
114 |
| - (parse-partial-sexp (point) calculate-lisp-indent-last-sexp |
115 |
| - 0 t) |
116 |
| - (backward-prefix-chars))))) |
117 |
| - ;; Point is at the point to indent under unless we are inside a string. |
118 |
| - ;; Call indentation hook except when overridden by lisp-indent-offset |
119 |
| - ;; or if the desired indentation has already been computed. |
120 |
| - (let ((normal-indent (current-column))) |
121 |
| - (cond ((elt state 3) |
122 |
| - ;; Inside a string, don't change indentation. |
123 |
| - nil) |
124 |
| - ((and (integerp lisp-indent-offset) containing-sexp) |
125 |
| - ;; Indent by constant offset |
126 |
| - (goto-char containing-sexp) |
127 |
| - (+ (current-column) lisp-indent-offset)) |
128 |
| - ;; in this case calculate-lisp-indent-last-sexp is not nil |
129 |
| - (calculate-lisp-indent-last-sexp |
130 |
| - (or |
131 |
| - ;; try to align the parameters of a known function |
132 |
| - (and lisp-indent-function |
133 |
| - (not retry) |
134 |
| - (funcall lisp-indent-function indent-point state)) |
135 |
| - ;; If the function has no special alignment |
136 |
| - ;; or it does not apply to this argument, |
137 |
| - ;; try to align a constant-symbol under the last |
138 |
| - ;; preceding constant symbol, if there is such one of |
139 |
| - ;; the last 2 preceding symbols, in the previous |
140 |
| - ;; uncommented line. |
141 |
| - (and (save-excursion |
142 |
| - (goto-char indent-point) |
143 |
| - (skip-chars-forward " \t") |
144 |
| - (looking-at ":")) |
145 |
| - ;; The last sexp may not be at the indentation |
146 |
| - ;; where it begins, so find that one, instead. |
147 |
| - (save-excursion |
148 |
| - (goto-char calculate-lisp-indent-last-sexp) |
149 |
| - ;; Handle prefix characters and whitespace |
150 |
| - ;; following an open paren. (Bug#1012) |
151 |
| - (backward-prefix-chars) |
152 |
| - (while (not (or (looking-back "^[ \t]*\\|([ \t]+" |
153 |
| - (line-beginning-position)) |
154 |
| - (and containing-sexp |
155 |
| - (>= (1+ containing-sexp) (point))))) |
156 |
| - (forward-sexp -1) |
157 |
| - (backward-prefix-chars)) |
158 |
| - (setq calculate-lisp-indent-last-sexp (point))) |
159 |
| - (> calculate-lisp-indent-last-sexp |
160 |
| - (save-excursion |
161 |
| - (goto-char (1+ containing-sexp)) |
162 |
| - (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t) |
163 |
| - (point))) |
164 |
| - (let ((parse-sexp-ignore-comments t) |
165 |
| - indent) |
166 |
| - (goto-char calculate-lisp-indent-last-sexp) |
167 |
| - (or (and (looking-at ":") |
168 |
| - (setq indent (current-column))) |
169 |
| - (and (< (line-beginning-position) |
170 |
| - (prog2 (backward-sexp) (point))) |
171 |
| - (looking-at ":") |
172 |
| - (setq indent (current-column)))) |
173 |
| - indent)) |
174 |
| - ;; another symbols or constants not preceded by a constant |
175 |
| - ;; as defined above. |
176 |
| - normal-indent)) |
177 |
| - ;; in this case calculate-lisp-indent-last-sexp is nil |
178 |
| - (desired-indent) |
179 |
| - (t |
180 |
| - normal-indent))))))) |
181 |
| - |
182 |
| - (when (< emacs-major-version 28) |
183 |
| - (advice-add #'calculate-lisp-indent :around #'wrap-calculate-lisp-indent)))) |
184 |
| - (flycheck-disabled-checkers . '(emacs-lisp-checkdoc)) |
185 |
| - (lsp--override-calculate-lisp-indent? . t) |
186 | 6 | (indent-tabs-mode . nil)))
|
0 commit comments