aboutsummaryrefslogtreecommitdiffstats
path: root/oni-csharp
diff options
context:
space:
mode:
authorGravatar Tom Willemse2020-03-02 17:59:42 -0800
committerGravatar Tom Willemse2020-03-02 17:59:42 -0800
commit68e796fb7c6242ac9a3941f62c03aa8ba0d0f178 (patch)
tree3008a816db6dde6cb21e17ab1516b76774673064 /oni-csharp
parentf082706a204de79f70ff9dcde9957eab8eeadc20 (diff)
downloademacs-config-68e796fb7c6242ac9a3941f62c03aa8ba0d0f178.tar.gz
emacs-config-68e796fb7c6242ac9a3941f62c03aa8ba0d0f178.zip
Add snippets to oni-csharp
Diffstat (limited to 'oni-csharp')
-rw-r--r--oni-csharp/Cask10
-rw-r--r--oni-csharp/oni-csharp.el133
-rw-r--r--oni-csharp/snippets/csharp-mode/testm9
3 files changed, 152 insertions, 0 deletions
diff --git a/oni-csharp/Cask b/oni-csharp/Cask
new file mode 100644
index 0000000..0355c12
--- /dev/null
+++ b/oni-csharp/Cask
@@ -0,0 +1,10 @@
+(source gnu)
+(source melpa)
+
+(package-file "./oni-csharp.el")
+
+(depends-on "oni-yasnippet" :git "../" :files ("oni-yasnippet.el"))
+
+(files
+ "*.el"
+ ("snippets" "./snippets/*"))
diff --git a/oni-csharp/oni-csharp.el b/oni-csharp/oni-csharp.el
new file mode 100644
index 0000000..e9a55f9
--- /dev/null
+++ b/oni-csharp/oni-csharp.el
@@ -0,0 +1,133 @@
+;;; oni-csharp.el --- C# Configuration -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Tom Willemse
+
+;; Author: Tom Willemse <tom@ryuslash.org>
+;; Keywords: local
+;; Version: 2020.0302.175435
+;; Package-Requires: (csharp-mode omnisharp oni-company oni-flycheck oni-yasnippet smartparens)
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; My C# configuration. This configuration enables ‘rainbow-delimiters-mode’.
+
+;;; Code:
+
+(require 'csharp-mode)
+(require 'yasnippet)
+
+(defconst oni-csharp-root
+ (file-name-directory
+ (or load-file-name
+ (buffer-file-name)))
+ "The directory where ‘oni-csharp’ was loaded from.")
+
+(defconst oni-csharp-snippets-dir
+ (expand-file-name "snippets" oni-csharp-root)
+ "The directory where ‘oni-csharp’ stores its snippets.")
+
+(defvar oni-csharp--projects (make-hash-table :test 'equal))
+
+(defun oni-csharp-collect-project-names ()
+ "Go through the current buffer and collect all the project names."
+ (interactive)
+ (clrhash oni-csharp--projects)
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward
+ (rx bol
+ "Project(\"{"
+ (group (minimal-match (1+ (or alphanumeric "-"))))
+ "}\") = \""
+ (group (minimal-match (1+ any)))
+ "\", \""
+ (minimal-match (1+ any))
+ "\", \"{"
+ (group (minimal-match (1+ any)))
+ "}\""
+ eol)
+ nil
+ :noerror)
+ (puthash (match-string-no-properties 3)
+ (match-string-no-properties 2)
+ oni-csharp--projects))))
+
+(defun oni-csharp-display-project-names ()
+ "Display the project names in the current buffer."
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (remove-overlays (point-min) (point-max) 'oni-csharp--overlayp t)
+ (while (re-search-forward
+ (rx bol
+ (zero-or-more whitespace)
+ "{"
+ (group (minimal-match (one-or-more (or alphanumeric "-"))))
+ "} = {"
+ (group (minimal-match (one-or-more (or alphanumeric "-"))))
+ "}"
+ eol)
+ nil
+ :noerror)
+ (let ((current-overlay (make-overlay (line-beginning-position) (line-end-position))))
+ (overlay-put current-overlay 'after-string
+ (propertize (format " => %s" (gethash (match-string 1) oni-csharp--projects))
+ 'face '(:foreground "#808080")))
+ (overlay-put current-overlay 'oni-csharp--overlayp t)
+ (overlay-put current-overlay 'evaporate t)))))
+
+(defun oni-csharp--auto-fill-mode ()
+ "Enable ‘auto-fill-mode’ only for comments."
+ (setq-local comment-auto-fill-only-comments t)
+ (auto-fill-mode))
+
+(defun oni-csharp-snippets-initialize ()
+ "Initialize the snippets for ‘oni-csharp’."
+ (when (boundp 'yas-snippet-dirs)
+ (add-to-list 'yas-snippet-dirs oni-csharp-snippets-dir t))
+ (yas-load-directory oni-csharp-snippets-dir))
+
+(with-eval-after-load 'company
+ (add-to-list 'company-backends
+ '(company-omnisharp :with company-yasnippet)))
+
+(add-hook 'csharp-mode-hook 'company-mode)
+(add-hook 'csharp-mode-hook 'electric-indent-local-mode)
+(add-hook 'csharp-mode-hook 'electric-pair-local-mode)
+(add-hook 'csharp-mode-hook 'flycheck-mode)
+(add-hook 'csharp-mode-hook 'omnisharp-mode)
+(add-hook 'csharp-mode-hook 'oni-csharp--auto-fill-mode)
+(add-hook 'csharp-mode-hook 'rainbow-delimiters-mode)
+(add-hook 'csharp-mode-hook 'smartparens-mode)
+
+(define-key csharp-mode-map (kbd "M-.") 'omnisharp-go-to-definition)
+(define-key csharp-mode-map (kbd "M-?") 'omnisharp-find-usages)
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.xaml\\'" . nxml-mode))
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.csproj\\'" . nxml-mode))
+
+;;;###autoload
+(with-eval-after-load 'csharp-mode
+ (with-eval-after-load 'yasnippet
+ (oni-csharp-snippets-initialize)))
+
+;;;###autoload(with-eval-after-load 'csharp-mode (require 'oni-csharp))
+
+(provide 'oni-csharp)
+;;; oni-csharp.el ends here
diff --git a/oni-csharp/snippets/csharp-mode/testm b/oni-csharp/snippets/csharp-mode/testm
new file mode 100644
index 0000000..4bd243d
--- /dev/null
+++ b/oni-csharp/snippets/csharp-mode/testm
@@ -0,0 +1,9 @@
+# -*- mode: snippet -*-
+# name: Test Method
+# key: testm
+# --
+[TestMethod]
+public void ${1:TestMethod}()
+{
+ $0
+} \ No newline at end of file