From 67159d71e5cecbb58922b62be2886a6ce17bf1d1 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 25 May 2023 00:18:35 -0700 Subject: [oni-csharp] Add command to add a file to ‘.csproj’ --- oni-csharp/oni-csharp.el | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'oni-csharp') diff --git a/oni-csharp/oni-csharp.el b/oni-csharp/oni-csharp.el index 1eb20a4..8451d93 100644 --- a/oni-csharp/oni-csharp.el +++ b/oni-csharp/oni-csharp.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2022.0202.115001 +;; Version: 2023.0525.001714 ;; 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 @@ -223,5 +223,37 @@ _cs_: Solution ;;;###autoload (add-to-list 'auto-mode-alist `(,(rx ".sln" eos) . csharp-solution-mode)) +(defun oni-csharp-add-file-to-project () + (interactive) + (let* ((file-name (buffer-file-name)) + (project-dir (locate-dominating-file file-name + (lambda (file) + (if (file-directory-p file) + (directory-files file nil (rx ".csproj" eos)) + (string-suffix-p ".csproj" file))))) + (project-files (directory-files project-dir nil (rx ".csproj" eos))) + (project-file (cl-case (length project-files) + (0 (error "No project files found in %s" project-dir)) + (1 (car project-files)) + (t (completing-read "Which project file? " project-files)))) + (relative-file-name (file-relative-name file-name project-dir)) + (project-file-absolute-path (expand-file-name project-file project-dir))) + (with-current-buffer (find-file-noselect project-file-absolute-path) + (save-excursion + (re-search-forward (rx "") + (re-search-backward (rx "")) + (forward-line) + (let ((start (line-beginning-position))) + (re-search-forward (rx "")) + (forward-line -1) + (indent-region start (line-end-position)) + (sort-lines nil start (line-end-position))) + (save-buffer))))) + (provide 'oni-csharp) ;;; oni-csharp.el ends here -- cgit v1.2.3-54-g00ecf