2019-04-09 00:25:56 +02:00
|
|
|
|
;;; oni-csharp.el --- C# Configuration -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2019 Tom Willemse
|
|
|
|
|
|
|
|
|
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
|
|
|
|
;; Keywords: local
|
2020-12-13 07:10:43 +01:00
|
|
|
|
;; Version: 2020.1212.221001
|
2020-07-14 18:59:37 +02:00
|
|
|
|
;; Package-Requires: (csharp-mode oni-company oni-flycheck oni-yasnippet oni-hydra oni-fci oni-lsp smartparens)
|
2019-04-09 00:25:56 +02:00
|
|
|
|
|
|
|
|
|
;; 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:
|
|
|
|
|
|
2020-02-06 07:42:33 +01:00
|
|
|
|
;; My C# configuration. This configuration enables ‘rainbow-delimiters-mode’.
|
2019-04-09 00:25:56 +02:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2020-03-03 04:53:09 +01:00
|
|
|
|
(require 'company)
|
2020-03-02 19:01:58 +01:00
|
|
|
|
(require 'csharp-mode)
|
2020-03-07 01:58:36 +01:00
|
|
|
|
(require 'hydra)
|
2020-03-03 02:59:42 +01:00
|
|
|
|
(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.")
|
2020-03-02 19:01:58 +01:00
|
|
|
|
|
2020-03-07 01:58:36 +01:00
|
|
|
|
(defcustom oni-csharp-devenv-executable
|
|
|
|
|
"\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\Common7\\IDE\\devenv.com\""
|
|
|
|
|
"The location of the devenv.com executable."
|
|
|
|
|
:group 'oni-csharp)
|
|
|
|
|
|
2019-04-09 23:05:09 +02:00
|
|
|
|
(defvar oni-csharp--projects (make-hash-table :test 'equal))
|
2019-04-09 00:25:56 +02:00
|
|
|
|
|
2020-03-07 01:58:36 +01:00
|
|
|
|
(defhydra oni-csharp-hydra (:color teal :hint nil)
|
|
|
|
|
"
|
2020-07-14 18:59:37 +02:00
|
|
|
|
^Compile^
|
|
|
|
|
^^------------
|
|
|
|
|
_cp_: Project
|
|
|
|
|
_cs_: Solution
|
|
|
|
|
^^
|
2020-03-07 01:58:36 +01:00
|
|
|
|
"
|
|
|
|
|
("cp" oni-csharp-compile-project)
|
2020-07-14 18:59:37 +02:00
|
|
|
|
("cs" oni-csharp-compile-solution))
|
2020-03-07 01:58:36 +01:00
|
|
|
|
|
|
|
|
|
(defun oni-csharp-compile-solution ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((compile-command (concat oni-csharp-devenv-executable " /Build Debug " (oni-csharp-locate-dominating-file-wildcard "*.sln"))))
|
|
|
|
|
(compile compile-command)))
|
|
|
|
|
|
|
|
|
|
(defun oni-csharp-locate-dominating-file-wildcard (filename)
|
|
|
|
|
(let (file-list
|
|
|
|
|
(default-directory default-directory))
|
|
|
|
|
(while (and (null file-list)
|
|
|
|
|
(string-prefix-p (projectile-project-root) default-directory))
|
|
|
|
|
(setq file-list (file-expand-wildcards filename t)
|
|
|
|
|
default-directory (file-name-directory (directory-file-name default-directory))))
|
|
|
|
|
(car file-list)))
|
|
|
|
|
|
|
|
|
|
(defun oni-csharp-compile-project ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((compile-command (concat oni-csharp-devenv-executable " /Build Debug " (oni-csharp-locate-dominating-file-wildcard "*.sln") " /project " (oni-csharp-locate-dominating-file-wildcard "*.csproj"))))
|
|
|
|
|
(compile compile-command)))
|
|
|
|
|
|
2019-04-09 23:05:09 +02:00
|
|
|
|
(defun oni-csharp-collect-project-names ()
|
2019-04-09 00:25:56 +02:00
|
|
|
|
"Go through the current buffer and collect all the project names."
|
|
|
|
|
(interactive)
|
2019-04-09 23:05:09 +02:00
|
|
|
|
(clrhash oni-csharp--projects)
|
2019-04-09 00:25:56 +02:00
|
|
|
|
(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)
|
2019-04-09 23:05:09 +02:00
|
|
|
|
oni-csharp--projects))))
|
2019-04-09 00:25:56 +02:00
|
|
|
|
|
|
|
|
|
(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
|
2019-04-09 23:05:09 +02:00
|
|
|
|
(propertize (format " => %s" (gethash (match-string 1) oni-csharp--projects))
|
2019-04-09 00:25:56 +02:00
|
|
|
|
'face '(:foreground "#808080")))
|
2019-04-09 23:05:09 +02:00
|
|
|
|
(overlay-put current-overlay 'oni-csharp--overlayp t)
|
|
|
|
|
(overlay-put current-overlay 'evaporate t)))))
|
2019-04-09 00:25:56 +02:00
|
|
|
|
|
2019-12-11 08:16:15 +01:00
|
|
|
|
(defun oni-csharp--auto-fill-mode ()
|
|
|
|
|
"Enable ‘auto-fill-mode’ only for comments."
|
|
|
|
|
(setq-local comment-auto-fill-only-comments t)
|
|
|
|
|
(auto-fill-mode))
|
|
|
|
|
|
2020-03-03 04:51:05 +01:00
|
|
|
|
;;;###autoload
|
2020-03-03 02:59:42 +01:00
|
|
|
|
(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))
|
|
|
|
|
|
2020-03-28 01:01:42 +01:00
|
|
|
|
(defun oni-csharp--update-style ()
|
|
|
|
|
"Set style rules according to personal (or recommended) preference."
|
|
|
|
|
(setf (alist-get 'arglist-intro c-offsets-alist) '+))
|
|
|
|
|
|
2020-12-11 05:52:52 +01:00
|
|
|
|
(add-hook 'csharp-mode-hook 'abbrev-mode)
|
2019-07-16 17:30:12 +02:00
|
|
|
|
(add-hook 'csharp-mode-hook 'company-mode)
|
|
|
|
|
(add-hook 'csharp-mode-hook 'electric-indent-local-mode)
|
|
|
|
|
(add-hook 'csharp-mode-hook 'flycheck-mode)
|
2020-07-14 18:59:37 +02:00
|
|
|
|
(add-hook 'csharp-mode-hook 'lsp)
|
2019-12-11 08:16:15 +01:00
|
|
|
|
(add-hook 'csharp-mode-hook 'oni-csharp--auto-fill-mode)
|
2020-03-28 01:01:42 +01:00
|
|
|
|
(add-hook 'csharp-mode-hook 'oni-csharp--update-style)
|
2020-02-06 07:42:33 +01:00
|
|
|
|
(add-hook 'csharp-mode-hook 'rainbow-delimiters-mode)
|
2020-02-29 22:48:39 +01:00
|
|
|
|
(add-hook 'csharp-mode-hook 'smartparens-mode)
|
2019-07-16 17:30:12 +02:00
|
|
|
|
|
2020-09-07 23:45:10 +02:00
|
|
|
|
(add-hook 'csharp-mode-hook
|
|
|
|
|
(if (fboundp 'display-fill-column-indicator-mode)
|
|
|
|
|
'display-fill-column-indicator-mode
|
|
|
|
|
'fci-mode))
|
|
|
|
|
|
2020-03-07 01:58:36 +01:00
|
|
|
|
(define-key csharp-mode-map (kbd "C-c SPC") 'oni-csharp-hydra/body)
|
2020-03-02 19:01:58 +01:00
|
|
|
|
|
2020-12-13 07:10:43 +01:00
|
|
|
|
(define-abbrev csharp-mode-abbrev-table "and" "&&" nil :system t)
|
|
|
|
|
(define-abbrev csharp-mode-abbrev-table "or" "||" nil :system t)
|
2020-12-11 05:52:52 +01:00
|
|
|
|
|
2020-01-29 06:47:34 +01:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.xaml\\'" . nxml-mode))
|
|
|
|
|
|
2020-04-07 21:01:05 +02:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.targets\\'" . nxml-mode))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.proj\\'". nxml-mode))
|
|
|
|
|
|
2020-01-29 07:15:41 +01:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.csproj\\'" . nxml-mode))
|
|
|
|
|
|
2020-09-08 00:11:27 +02:00
|
|
|
|
(with-eval-after-load 'autoinsert
|
|
|
|
|
(add-to-list 'auto-insert-alist
|
|
|
|
|
`(,(rx ".proj" string-end)
|
|
|
|
|
nil
|
|
|
|
|
"<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" ToolsVersion=\"4.0\">\n " _ "\n</Project>")))
|
2020-08-28 07:31:28 +02:00
|
|
|
|
|
2020-03-03 02:59:42 +01:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(with-eval-after-load 'csharp-mode
|
|
|
|
|
(with-eval-after-load 'yasnippet
|
|
|
|
|
(oni-csharp-snippets-initialize)))
|
|
|
|
|
|
2019-07-16 17:30:12 +02:00
|
|
|
|
;;;###autoload(with-eval-after-load 'csharp-mode (require 'oni-csharp))
|
|
|
|
|
|
2019-04-09 00:25:56 +02:00
|
|
|
|
(provide 'oni-csharp)
|
|
|
|
|
;;; oni-csharp.el ends here
|