From 4e1ff8893d17bcb7aea4a6963296d998d6da7037 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 6 Mar 2020 16:58:36 -0800 Subject: Add some C# commands with a hydra --- oni-csharp/oni-csharp.el | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/oni-csharp/oni-csharp.el b/oni-csharp/oni-csharp.el index 5214f59..dbe8d90 100644 --- a/oni-csharp/oni-csharp.el +++ b/oni-csharp/oni-csharp.el @@ -4,8 +4,8 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2020.0302.195150 -;; Package-Requires: (csharp-mode omnisharp oni-company oni-flycheck oni-yasnippet smartparens) +;; Version: 2020.0306.164345 +;; 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 ;; it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ (require 'company) (require 'csharp-mode) +(require 'hydra) (require 'yasnippet) (defconst oni-csharp-root @@ -40,8 +41,47 @@ (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^ ^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 () "Go through the current buffer and collect all the project names." (interactive) @@ -117,6 +157,7 @@ (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 "C-c SPC") 'oni-csharp-hydra/body) ;;;###autoload (add-to-list 'auto-mode-alist '("\\.xaml\\'" . nxml-mode)) -- cgit v1.2.3-54-g00ecf