emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql 944de63e9d 298/427: Add functions to fix vector in


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 944de63e9d 298/427: Add functions to fix vector indentation.
Date: Tue, 13 Dec 2022 02:59:53 -0500 (EST)

branch: elpa/emacsql
commit 944de63e9d34654f1f3485c57ed523394d9b00c5
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Add functions to fix vector indentation.
---
 README.md  | 22 ++++++++++++++++++++++
 emacsql.el | 26 ++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/README.md b/README.md
index 8a1758ac67..0714831c59 100644
--- a/README.md
+++ b/README.md
@@ -322,6 +322,28 @@ from the command line and allows for storage of Emacs 
richer data
 types. This is an efficient, ACID-compliant database specifically for
 Emacs.
 
+## Emacs Lisp Indentation Annoyance
+
+By default, `emacs-lisp-mode` indents vectors as if they were regular
+function calls.
+
+```el
+;; Ugly indentation!
+(emacsql db [:select *
+                     :from people
+                     :where (> age 60)])
+```
+
+Calling the function `emacsql-fix-vector-indentation` (interactive)
+advises the major mode to fix this annoyance.
+
+```el
+;; Such indent!
+(emacsql db [:select *
+             :from people
+             :where (> age 60)])
+```
+
 ## Contributing and Extending
 
 You'll need to install [Cask][cask], which is required for compilation
diff --git a/emacsql.el b/emacsql.el
index 0840c3b09d..cff35da308 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -380,4 +380,30 @@ A prefix argument causes the SQL to be printed into the 
current buffer."
             (emacsql-show-sql sql)))
       (user-error "Invalid SQL: %S" sexp))))
 
+;; Fix Emacs' broken vector indentation:
+
+(defun emacsql--inside-vector-p ()
+  "Return non-nil if point is inside a vector expression."
+  (let ((start (point)))
+    (save-excursion
+      (backward-paragraph)
+      (let ((containing-sexp (elt (parse-partial-sexp (point) start) 1)))
+        (when containing-sexp
+          (setf (point) containing-sexp)
+          (looking-at "\\["))))))
+
+(defadvice calculate-lisp-indent (around emacsql-vector-indent disable)
+  "Don't indent vectors in `emacs-lisp-mode' like lists."
+  (if (emacsql--inside-vector-p)
+      (let ((lisp-indent-offset 1))
+        ad-do-it)
+      ad-do-it))
+
+(defun emacsql-fix-vector-indentation ()
+  "When called, advise `calculate-lisp-indent' to stop indenting vectors.
+Once activate, vector contents no longer indent like lists."
+  (interactive)
+  (ad-enable-advice 'calculate-lisp-indent 'around 'emacsql-vector-indent)
+  (ad-activate 'calculate-lisp-indent))
+
 ;;; emacsql.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]