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

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

[nongnu] elpa/go-mode e8674fe 437/495: Expand electric indent config a b


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode e8674fe 437/495: Expand electric indent config a bit
Date: Sat, 7 Aug 2021 09:06:04 -0400 (EDT)

branch: elpa/go-mode
commit e8674febca6caf6b5030808e1b10677a9fd8f503
Author: Muir Manders <muir@retailnext.net>
Commit: Peter Sanford <psanford@sanford.io>

    Expand electric indent config a bit
    
    Add an electric indent function to trigger reindent after typing "//",
    "/*", or "case ". This makes it less annoying when you are adding
    comments to case statements or adding a new case statement itself.
    
    Also add ":" to electric-indent-chars. This will trigger reindent
    after typing labels.
---
 go-mode.el | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 11646cc..bbc0de2 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1113,6 +1113,21 @@ Function result is a unparenthesized type or a parameter 
list."
 This is intended to be called from `before-change-functions'."
   (setq go-dangling-cache (make-hash-table :test 'eql)))
 
+(defun go--electric-indent-function (inserted-char)
+  (cond
+   ;; Indent after starting a "//" or "/*" comment.
+   ;; This is handy for comments above "case" statements.
+   ((or (eq inserted-char ?/) (eq inserted-char ?*))
+    (when (eq (char-before (1- (point))) ?/)
+      'do-indent))
+
+   ((eq inserted-char ? )
+    (and
+     (eq (char-before (- (point) 1)) ?e)
+     (eq (char-before (- (point) 2)) ?s)
+     (eq (char-before (- (point) 3)) ?a)
+     (eq (char-before (- (point) 4)) ?c)))))
+
 ;;;###autoload
 (define-derived-mode go-mode prog-mode "Go"
   "Major mode for editing Go source text.
@@ -1196,8 +1211,9 @@ with goflymake \(see URL 
`https://github.com/dougm/goflymake'), gocode
   (set (make-local-variable 'parse-sexp-lookup-properties) t)
   (set (make-local-variable 'syntax-propertize-function) 
#'go-propertize-syntax)
 
-  (if (boundp 'electric-indent-chars)
-      (set (make-local-variable 'electric-indent-chars) '(?\n ?} ?\))))
+  (when (boundp 'electric-indent-chars)
+    (set (make-local-variable 'electric-indent-chars) '(?\n ?} ?\) ?:))
+    (add-hook 'electric-indent-functions #'go--electric-indent-function nil t))
 
   (set (make-local-variable 'compilation-error-screen-columns) nil)
 



reply via email to

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