diff options
| author | Lars Ingebrigtsen | 2022-04-13 05:07:30 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-04-13 05:07:47 +0200 |
| commit | 88a04ea985180d1fd619c4a6540fb117a1d59d9e (patch) | |
| tree | 6978ed1506e30fbaa1f9c881d8754b19ae94987b /lisp | |
| parent | 1c1ae6ba802cc5813fa6f8f90f21050aae6bb459 (diff) | |
| download | emacs-88a04ea985180d1fd619c4a6540fb117a1d59d9e.tar.gz emacs-88a04ea985180d1fd619c4a6540fb117a1d59d9e.zip | |
Tweak how `M-q' in emacs-lisp-mode works
* lisp/emacs-lisp/lisp-mode.el (lisp-fill-paragraph): Only fill as
strings inside strings (bug#31656).
(lisp--fill-line-simple): New function to do simple sexp-based
filling.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 7df40e36f8f..e7c3a4b64f5 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -1436,29 +1436,49 @@ and initial semicolons." | |||
| 1436 | (derived-mode-p 'emacs-lisp-mode)) | 1436 | (derived-mode-p 'emacs-lisp-mode)) |
| 1437 | emacs-lisp-docstring-fill-column | 1437 | emacs-lisp-docstring-fill-column |
| 1438 | fill-column))) | 1438 | fill-column))) |
| 1439 | (save-restriction | 1439 | (let ((ppss (syntax-ppss)) |
| 1440 | (start (point))) | ||
| 1440 | (save-excursion | 1441 | (save-excursion |
| 1441 | (let ((ppss (syntax-ppss)) | 1442 | (save-restriction |
| 1442 | (start (point))) | 1443 | ;; If we're not inside a string, then do very basic |
| 1443 | ;; If we're in a string, then narrow (roughly) to that | 1444 | ;; filling. This avoids corrupting embedded strings in |
| 1444 | ;; string before filling. This avoids filling Lisp | 1445 | ;; code. |
| 1445 | ;; statements that follow the string. | 1446 | (if (not (ppss-comment-or-string-start ppss)) |
| 1446 | (when (ppss-string-terminator ppss) | 1447 | (lisp--fill-line-simple) |
| 1447 | (goto-char (ppss-comment-or-string-start ppss)) | 1448 | ;; If we're in a string, then narrow (roughly) to that |
| 1448 | (beginning-of-line) | 1449 | ;; string before filling. This avoids filling Lisp |
| 1449 | ;; The string may be unterminated -- in that case, don't | 1450 | ;; statements that follow the string. |
| 1450 | ;; narrow. | 1451 | (when (ppss-string-terminator ppss) |
| 1451 | (when (ignore-errors | 1452 | (goto-char (ppss-comment-or-string-start ppss)) |
| 1452 | (progn | 1453 | ;; The string may be unterminated -- in that case, don't |
| 1453 | (forward-sexp 1) | 1454 | ;; narrow. |
| 1454 | t)) | 1455 | (when (ignore-errors |
| 1455 | (narrow-to-region (ppss-comment-or-string-start ppss) | 1456 | (progn |
| 1456 | (point)))) | 1457 | (forward-sexp 1) |
| 1457 | ;; Move back to where we were. | 1458 | t)) |
| 1459 | (narrow-to-region (ppss-comment-or-string-start ppss) | ||
| 1460 | (point)))) | ||
| 1461 | ;; Move back to where we were. | ||
| 1462 | (goto-char start) | ||
| 1463 | (fill-paragraph justify))))))) | ||
| 1464 | ;; Never return nil. | ||
| 1465 | t) | ||
| 1466 | |||
| 1467 | (defun lisp--fill-line-simple () | ||
| 1468 | (narrow-to-region (line-beginning-position) (line-end-position)) | ||
| 1469 | (goto-char (point-min)) | ||
| 1470 | (while (and (not (eobp)) | ||
| 1471 | (re-search-forward "\\_>" nil t)) | ||
| 1472 | (when (> (current-column) fill-column) | ||
| 1473 | (let ((start (point))) | ||
| 1474 | (backward-sexp) | ||
| 1475 | (if (looking-back "[[(]" (point-min)) | ||
| 1458 | (goto-char start) | 1476 | (goto-char start) |
| 1459 | (fill-paragraph justify))))) | 1477 | (skip-chars-backward " \t") |
| 1460 | ;; Never return nil. | 1478 | (insert "\n") |
| 1461 | t)) | 1479 | (forward-sexp)))) |
| 1480 | (unless (eobp) | ||
| 1481 | (forward-char 1)))) | ||
| 1462 | 1482 | ||
| 1463 | (defun indent-code-rigidly (start end arg &optional nochange-regexp) | 1483 | (defun indent-code-rigidly (start end arg &optional nochange-regexp) |
| 1464 | "Indent all lines of code, starting in the region, sideways by ARG columns. | 1484 | "Indent all lines of code, starting in the region, sideways by ARG columns. |