1
0
Fork 0

Add some C# commands with a hydra

This commit is contained in:
Tom Willemse 2020-03-06 16:58:36 -08:00
parent 821d6c030e
commit 4e1ff8893d

View file

@ -4,8 +4,8 @@
;; Author: Tom Willemse <tom@ryuslash.org> ;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local ;; Keywords: local
;; Version: 2020.0302.195150 ;; Version: 2020.0306.164345
;; Package-Requires: (csharp-mode omnisharp oni-company oni-flycheck oni-yasnippet smartparens) ;; Package-Requires: (csharp-mode omnisharp oni-company oni-flycheck oni-yasnippet oni-hydra smartparens)
;; This program is free software; you can redistribute it and/or modify ;; 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 ;; it under the terms of the GNU General Public License as published by
@ -28,6 +28,7 @@
(require 'company) (require 'company)
(require 'csharp-mode) (require 'csharp-mode)
(require 'hydra)
(require 'yasnippet) (require 'yasnippet)
(defconst oni-csharp-root (defconst oni-csharp-root
@ -40,8 +41,47 @@
(expand-file-name "snippets" oni-csharp-root) (expand-file-name "snippets" oni-csharp-root)
"The directory where oni-csharp stores its snippets.") "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)) (defvar oni-csharp--projects (make-hash-table :test 'equal))
(defhydra oni-csharp-hydra (:color teal :hint nil)
"
^Compile^ ^Refactor^ ^Maintenance^
^^^^^^------------------------------------
_cp_: Project _rr_: Rename _ms_: Start Omnisharp
_cs_: Solution ^^ _mr_: Reload Solution
^^ ^^ _mS_: Stop Omnisharp
"
("cp" oni-csharp-compile-project)
("cs" oni-csharp-compile-solution)
("rr" omnisharp-rename)
("ms" omnisharp-start-omnisharp-server)
("mr" omnisharp-reload-solution)
("mS" omnisharp-stop-server))
(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 () (defun oni-csharp-collect-project-names ()
"Go through the current buffer and collect all the project names." "Go through the current buffer and collect all the project names."
(interactive) (interactive)
@ -117,6 +157,7 @@
(define-key csharp-mode-map (kbd "M-.") 'omnisharp-go-to-definition) (define-key csharp-mode-map (kbd "M-.") 'omnisharp-go-to-definition)
(define-key csharp-mode-map (kbd "M-?") 'omnisharp-find-usages) (define-key csharp-mode-map (kbd "M-?") 'omnisharp-find-usages)
(define-key csharp-mode-map (kbd "C-c SPC") 'oni-csharp-hydra/body)
;;;###autoload ;;;###autoload
(add-to-list 'auto-mode-alist '("\\.xaml\\'" . nxml-mode)) (add-to-list 'auto-mode-alist '("\\.xaml\\'" . nxml-mode))