[oni-csharp] Add csharp-solution-mode major mode
This major mode will be for viewing and editing the solution file. Right now it just parses the solution file and displays some of the project names instead of the GUIDs to make it more human readable.
This commit is contained in:
parent
df8ad7f733
commit
d4eea37a8f
1 changed files with 59 additions and 49 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||||
;; Keywords: local
|
;; Keywords: local
|
||||||
;; Version: 2022.0105.161232
|
;; Version: 2022.0202.115001
|
||||||
;; Package-Requires: (csharp-mode oni-company oni-flycheck oni-yasnippet oni-hydra oni-lsp oni-smartparens)
|
;; 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
|
;; This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -78,54 +78,6 @@ _cs_: Solution
|
||||||
(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"))))
|
(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)))
|
(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 ()
|
(defun oni-csharp--auto-fill-mode ()
|
||||||
"Enable ‘auto-fill-mode’ only for comments."
|
"Enable ‘auto-fill-mode’ only for comments."
|
||||||
(setq-local comment-auto-fill-only-comments t)
|
(setq-local comment-auto-fill-only-comments t)
|
||||||
|
@ -203,5 +155,63 @@ _cs_: Solution
|
||||||
(with-eval-after-load 'yasnippet
|
(with-eval-after-load 'yasnippet
|
||||||
(oni-csharp-snippets-initialize)))
|
(oni-csharp-snippets-initialize)))
|
||||||
|
|
||||||
|
;;; Solution mode
|
||||||
|
|
||||||
|
(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)))))
|
||||||
|
|
||||||
|
(define-derived-mode csharp-solution-mode prog-mode "Sln"
|
||||||
|
"A major mode for viewing and editing C# ‘.sln’ files."
|
||||||
|
(oni-csharp-collect-project-names)
|
||||||
|
(oni-csharp-display-project-names))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(add-to-list 'auto-mode-alist `(,(rx ".sln" eos) . csharp-solution-mode))
|
||||||
|
|
||||||
(provide 'oni-csharp)
|
(provide 'oni-csharp)
|
||||||
;;; oni-csharp.el ends here
|
;;; oni-csharp.el ends here
|
||||||
|
|
Loading…
Reference in a new issue