[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 5c3a797 129/495: Handle indentation for multi-line
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 5c3a797 129/495: Handle indentation for multi-line function declarations correctly |
Date: |
Sat, 7 Aug 2021 09:04:58 -0400 (EDT) |
branch: elpa/go-mode
commit 5c3a797f993efbb31a96aad40eb28f64d8faa73d
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
Handle indentation for multi-line function declarations correctly
Closes gh-15
---
go-mode.el | 40 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 2fe519e..bf57475 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -237,6 +237,28 @@ STOP-AT-STRING is not true, over strings."
(puthash cur-line val go-dangling-cache))))
val))
+(defun go--at-function-definition ()
+ "Return non-nil if point is on the opening curly brace of a
+function definition.
+
+We do this by first calling (beginning-of-defun), which will take
+us to the start of *some* function. We then look for the opening
+curly brace of that function and compare its position against the
+curly brace we are checking. If they match, we return non-nil."
+ (if (= (char-after) ?\{)
+ (save-excursion
+ (let ((old-point (point))
+ start-nesting)
+ (beginning-of-defun)
+ (when (looking-at "func ")
+ (setq start-nesting (go-paren-level))
+ (skip-chars-forward "^{")
+ (while (> (go-paren-level) start-nesting)
+ (forward-char)
+ (skip-chars-forward "^{") 0)
+ (if (and (= (go-paren-level) start-nesting) (= old-point (point)))
+ t))))))
+
(defun go-goto-opening-parenthesis (&optional char)
(let ((start-nesting (go-paren-level)))
(while (and (not (bobp))
@@ -249,6 +271,20 @@ STOP-AT-STRING is not true, over strings."
(go-goto-beginning-of-string-or-comment)
(backward-char))))))
+(defun go--indentation-for-opening-parenthesis ()
+ "Return the semantic indentation for the current opening parenthesis.
+
+If point is on an opening curly brace and said curly brace
+belongs to a function declaration, the indentation of the func
+keyword will be returned. Otherwise the indentation of the
+current line will be returned."
+ (save-excursion
+ (if (go--at-function-definition)
+ (progn
+ (beginning-of-defun)
+ (current-indentation))
+ (current-indentation))))
+
(defun go-indentation-at-point ()
(save-excursion
(let (start-nesting)
@@ -262,7 +298,7 @@ STOP-AT-STRING is not true, over strings."
(go-goto-opening-parenthesis (char-after))
(if (go-previous-line-has-dangling-op-p)
(- (current-indentation) tab-width)
- (current-indentation)))
+ (go--indentation-for-opening-parenthesis)))
((progn (go--backward-irrelevant t) (looking-back
go-dangling-operators-regexp))
;; only one nesting for all dangling operators in one operation
(if (go-previous-line-has-dangling-op-p)
@@ -273,7 +309,7 @@ STOP-AT-STRING is not true, over strings."
((progn (go-goto-opening-parenthesis) (< (go-paren-level)
start-nesting))
(if (go-previous-line-has-dangling-op-p)
(current-indentation)
- (+ (current-indentation) tab-width)))
+ (+ (go--indentation-for-opening-parenthesis) tab-width)))
(t
(current-indentation))))))
- [nongnu] elpa/go-mode d900f72 060/495: extend indentation_tests/gh-15.go, (continued)
- [nongnu] elpa/go-mode d900f72 060/495: extend indentation_tests/gh-15.go, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 846ed32 063/495: optimizations, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e184d60 070/495: Replace go--directory-dirs with find-lisp-find-files-internal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 56ab2c8 088/495: make sure kill-line in go-remove-unused-imports includes \n, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0b32caa 093/495: fix usage of url-* functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1fdbcbf 095/495: use line-number-at-pos isntead of count-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7512759 104/495: Merge branch 'master' of https://github.com/imarko/go-mode.el into imarko-master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a52724b 116/495: use own history for godoc command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fb3e413 118/495: fix list markup in readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0f0fe35 127/495: actually avoid using process-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5c3a797 129/495: Handle indentation for multi-line function declarations correctly,
ELPA Syncer <=
- [nongnu] elpa/go-mode f5c445c 130/495: improve godef related documentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 97f55b8 131/495: style changes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b97cfea 133/495: godef-jump: use push-mark., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a18b3f3 134/495: style change, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 55295da 128/495: formatting, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 50412f7 136/495: add gitignore, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode ec73086 157/495: remove unused code, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5fd1c63 156/495: document go-goto-opening-parenthesis, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f4d2977 158/495: add go-coverage to display coverage information, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a5d5039 161/495: use go--goto-line where applicable, ELPA Syncer, 2021/08/07