[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/csharp-mode 49d213a 045/459: Remove csharp-insert-open-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/csharp-mode 49d213a 045/459: Remove csharp-insert-open-brace. Recommend electric-pair-mode instead. |
Date: |
Sun, 22 Aug 2021 13:58:52 -0400 (EDT) |
branch: externals/csharp-mode
commit 49d213a708bcb985898033fce55e111228c02816
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: Jostein Kjønigsen <jostein@kjonigsen.net>
Remove csharp-insert-open-brace. Recommend electric-pair-mode instead.
Closes https://github.com/josteink/csharp-mode/issues/11
---
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 831bd53 108/459: Fix "make clean"., (continued)
- [elpa] externals/csharp-mode 831bd53 108/459: Fix "make clean"., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode ba36d6c 105/459: Replace `flet` with `letrec`, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 494cbd9 106/459: Merge pull request #45 from wasamasa/fix-flet-warning, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode a182957 112/459: Update changelog., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 03e6200 109/459: Emacs: Tentative fix for fontification issues., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 64eb7db 114/459: Merge pull request #47 from josteink/feature-cl-lib, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 165a128 028/459: Update maintainer-ship and new repo-URL., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode ac6a1ff 036/459: Don't package stuff we only need for the build., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode f000c97 037/459: Add link to Travis., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 0762f78 038/459: remove the debug (message "Loading ...") forms, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 49d213a 045/459: Remove csharp-insert-open-brace. Recommend electric-pair-mode instead.,
ELPA Syncer <=
- [elpa] externals/csharp-mode 3af278a 070/459: Parse the base directory from MSBuild to support finding errors in dependency projects., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode e73ad4e 071/459: Merge pull request #30 from binki/compilation-regexps, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode baef28a 072/459: fix error highlighting and use filename functions, ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 2303fe0 074/459: Add msbuild and xbuild log-files for ERT-testing., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 69eaa1a 080/459: Add tests for compilation-mode regexps., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 7ef0c5c 032/459: Configure travis-build., ELPA Syncer, 2021/08/22
- [elpa] externals/csharp-mode 2fe1a72 033/459: Fix error in path in makefile., ELPA Syncer, 2021/08/22
- [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