1
0
Fork 0
emacs-config/oni-csharp/oni-csharp.el
Tom Willemse 8a67063ae4 [oni-csharp] Change indentation for argument list continuations
Previously:

    public void Foo(TypeA arg1,
                    TypeB arg2)
    {

Now:

    public void Foo(TypeA arg1,
        TypeB arg2)
    {
2022-01-05 16:12:51 -08:00

189 lines
6.7 KiB
EmacsLisp
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; oni-csharp.el --- C# Configuration -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Tom Willemse
;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2022.0105.161232
;; Package-Requires: (csharp-mode oni-company oni-flycheck oni-yasnippet oni-hydra oni-lsp oni-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 'company)
(require 'csharp-mode)
(require 'hydra)
(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.")
(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)
(defvar oni-csharp--projects (make-hash-table :test 'equal))
(defhydra oni-csharp-hydra (:color teal :hint nil)
"
^Compile^
^^------------
_cp_: Project
_cs_: Solution
^^
"
("cp" oni-csharp-compile-project)
("cs" oni-csharp-compile-solution))
(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)))
(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))
(defun oni-csharp--update-style ()
"Set style rules according to personal (or recommended) preference."
(c-set-offset 'arglist-intro '+)
(c-set-offset 'arglist-cont-nonempty '+))
(add-hook 'csharp-mode-hook 'abbrev-mode)
(add-hook 'csharp-mode-hook 'company-mode)
(add-hook 'csharp-mode-hook 'display-fill-column-indicator-mode)
(add-hook 'csharp-mode-hook 'electric-indent-local-mode)
(add-hook 'csharp-mode-hook 'flycheck-mode)
(add-hook 'csharp-mode-hook 'lsp)
(add-hook 'csharp-mode-hook 'oni-csharp--auto-fill-mode)
(add-hook 'csharp-mode-hook 'oni-csharp--update-style)
(add-hook 'csharp-mode-hook 'rainbow-delimiters-mode)
(add-hook 'csharp-mode-hook 'smartparens-mode)
(define-key csharp-mode-map (kbd "C-c SPC") 'oni-csharp-hydra/body)
(define-abbrev csharp-mode-abbrev-table "and" "&&" nil :system t)
(define-abbrev csharp-mode-abbrev-table "or" "||" nil :system t)
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.xaml\\'" . nxml-mode))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.targets\\'" . nxml-mode))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.proj\\'". nxml-mode))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.csproj\\'" . nxml-mode))
(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>")))
(with-eval-after-load 'lsp-csharp
(when (eq system-type 'windows-nt)
(setq lsp-csharp-omnisharp-roslyn-server-dir
(expand-file-name "~/scoop/apps/omnisharp/current"))))
(with-eval-after-load 'csharp-mode
(with-eval-after-load 'yasnippet
(oni-csharp-snippets-initialize)))
(provide 'oni-csharp)
;;; oni-csharp.el ends here