[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/csharp-mode a6eb8bd 047/459: Merge changes from branch
From: |
ELPA Syncer |
Subject: |
[elpa] externals/csharp-mode a6eb8bd 047/459: Merge changes from branch 'devel' |
Date: |
Sun, 22 Aug 2021 13:58:53 -0400 (EDT) |
branch: externals/csharp-mode
commit a6eb8bdac05ec8b5a5f1e0e51bf890265cc983f0
Merge: d33cfb6 49d213a
Author: Jesse Black <jesse.w.black@gmail.com>
Commit: Jesse Black <jesse.w.black@gmail.com>
Merge changes from branch 'devel'
---
csharp-mode.el | 160 +--------------------------------------------------------
1 file changed, 2 insertions(+), 158 deletions(-)
diff --git a/csharp-mode.el b/csharp-mode.el
index 0558b2a..4a07468 100644
--- a/csharp-mode.el
+++ b/csharp-mode.el
@@ -48,7 +48,8 @@
;;
;; - automagic code-doc generation when you type three slashes.
;;
-;; - intelligent insertion of matched pairs of curly braces.
+;; - compatible with electric-pair-mode for intelligent insertion
+;; of matched braces, quotes, etc.
;;
;; - imenu integration - generates an index of namespaces, classes,
;; interfaces, methods, and properties for easy navigation within
@@ -550,162 +551,6 @@ comment at the start of cc-engine.el for more info."
-(defun csharp-insert-open-brace ()
- "Intelligently insert a pair of curly braces. This fn should be
-bound to the open-curly brace, with
-
- (local-set-key (kbd \"{\") 'csharp-insert-open-brace)
-
-The default binding for an open curly brace in cc-modes is often
-`c-electric-brace' or `skeleton-pair-insert-maybe'. The former
-can be configured to insert newlines around braces in various
-syntactic positions. The latter inserts a pair of braces and
-then does not insert a newline, and does not indent.
-
-This fn provides another option, with some additional
-intelligence for csharp-mode. When you type an open curly, the
-appropriate pair of braces appears, with spacing and indent set
-in a context-sensitive manner:
-
- - Within a string literal, you just get a pair of braces, and
- point is set between them. This works for String.Format()
- purposes.
-
- - Following = or [], as in an array assignment, you get a pair
- of braces, with two intervening spaces, with a semincolon
- appended. Point is left between the braces.
-
- - Following \"new Foo\", it's an object initializer. You get:
- newline, open brace, newline, newline, close, semi. Point is
- left on the blank line between the braces. Unless the object
- initializer is within an array initializer, in which case, no
- newlines, and the semi is replaced with a comma. (Try it to
- see what this means).
-
- - Following => , implying a lambda, you get an open/close pair,
- with two intervening spaces, no semicolon, and point on the
- 2nd space.
-
- - Otherwise, you get a newline, the open curly, followed by
- an empty line and the closing curly on the line following,
- with point on the empty line.
-
-
-There may be another way to get this to happen appropriately just
-within emacs, but I could not figure out how to do it. So I
-wrote this alternative.
-
- "
- (interactive)
- (let
- (tpoint
- (in-string (string= (csharp-in-literal) "string"))
- (preceding3
- (save-excursion
- (and
- (skip-chars-backward " \t")
- (> (- (point) 2) (point-min))
- (buffer-substring-no-properties (point) (- (point) 3)))))
- (one-word-back
- (save-excursion
- (backward-word 2)
- (thing-at-point 'word))))
-
- (cond
-
- ;; Case 1: inside a string literal?
- ;; --------------------------------------------
- ;; If so, then just insert a pair of braces and put the point
- ;; between them. The most common case is a format string for
- ;; String.Format() or Console.WriteLine().
- (in-string
- (self-insert-command 1)
- (insert "}")
- (backward-char))
-
- ;; Case 2: the open brace starts an array initializer.
- ;; --------------------------------------------
- ;; When the last non-space was an equals sign or square brackets,
- ;; then it's an initializer.
- ((save-excursion
- (and (c-safe (backward-sexp) t)
- (looking-at "\\(\\w+\\b *=\\|[[]]+\\)")))
- (self-insert-command 1)
- (insert " };")
- (backward-char 3))
-
- ;; Case 3: the open brace starts an instance initializer
- ;; --------------------------------------------
- ;; If one-word-back was "new", then it's an object initializer.
- ((string= one-word-back "new")
- (csharp-log 2 "object initializer")
- (setq tpoint (point)) ;; prepare to indent-region later
- (backward-word 2)
- (c-backward-syntactic-ws)
- (if (or (eq (char-before) ?,) ;; comma
- (and (eq (char-before) 123) ;; open curly
- (progn (backward-char)
- (c-backward-syntactic-ws)
- (looking-back "\\[\\]"))))
- (progn
- ;; within an array - emit no newlines
- (goto-char tpoint)
- (self-insert-command 1)
- (insert " },")
- (backward-char 3))
-
- (progn
- (goto-char tpoint)
- (newline)
- (self-insert-command 1)
- (newline-and-indent)
- (newline)
- (insert "};")
- (c-indent-region tpoint (point))
- (forward-line -1)
- (indent-according-to-mode)
- (end-of-line))))
-
-
- ;; Case 4: a lambda initialier.
- ;; --------------------------------------------
- ;; If the open curly follows =>, then it's a lambda initializer.
- ((string= (substring preceding3 -2) "=>")
- (csharp-log 2 "lambda init")
- (self-insert-command 1)
- (insert " }")
- (backward-char 2))
-
- ;; else, it's a new scope. (if, while, class, etc)
- (t
- (save-excursion
- (csharp-log 2 "new scope")
- (set-mark (point)) ;; prepare to indent-region later
- ;; check if the prior sexp is on the same line
- (if (save-excursion
- (let ((curline (line-number-at-pos))
- (aftline (progn
- (if (c-safe (backward-sexp) t)
- (line-number-at-pos)
- -1))))
- (= curline aftline)))
- (newline-and-indent))
- (self-insert-command 1)
- (c-indent-line-or-region)
- (end-of-line)
- (newline)
- (insert "}")
- ;;(c-indent-command) ;; not sure of the difference here
- (c-indent-line-or-region)
- (forward-line -1)
- (end-of-line)
- (newline-and-indent)
- ;; point ends up on an empty line, within the braces, properly indented
- (setq tpoint (point)))
-
- (goto-char tpoint)))))
-
-
;; ==================================================================
;; end of csharp-mode utility and feature defuns
;; ==================================================================
@@ -4541,7 +4386,6 @@ Key bindings:
(c-common-init 'csharp-mode)
(local-set-key (kbd "/") 'csharp-maybe-insert-codedoc)
- (local-set-key (kbd "{") 'csharp-insert-open-brace)
;; Need the following for parse-partial-sexp to work properly with
;; verbatim literal strings Setting this var to non-nil tells
- [elpa] externals/csharp-mode 3d0f86b 043/459: Updated readme., (continued)
- [elpa] externals/csharp-mode 3d0f86b 043/459: Updated readme., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode fff8cb1 053/459: Merge branch 'devel', ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 689dd8b 056/459: make c# style the default style, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 421d3de 062/459: remove aspx code, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 962478e 057/459: Merge branch 'devel', ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 2d13a9c 058/459: Add very broad build-level test., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 723341b 067/459: Fix incorrect-code tags in readme., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode a86839b 064/459: Merged from master., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 0a2a3b0 066/459: Fix Emacs-lockup during fontification., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode f2fda33 041/459: Fix errors in `make package`., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode a6eb8bd 047/459: Merge changes from branch 'devel',
ELPA Syncer <=
- [elpa] externals/csharp-mode 6289cfd 051/459: Fix broken byte-compile., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 1f2fc21 055/459: Remove obsolete workarounds from README., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode d7ba765 063/459: Merge changes from devel., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode ed628e6 075/459: Attempt fix compilation-mode regexps for both xbuild & msbuild., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 3c2f942 087/459: Merge pull request #34 from binki/master, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 31eebb9 079/459: create separate compilation regexps for xbuild, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 42ca773 097/459: Fix runtime warnings about obsolete Emacs-functions., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 0779fe4 107/459: Update changelog., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 1f0465b 126/459: Fix comments, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 6efd459 127/459: Stylistic fixes, ELPA Syncer, 2021/08/22