From c5125ba976fc06f13712f97a1fc36de469d1b8b3 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Mon, 25 Aug 2025 10:56:38 +0200 Subject: [PATCH] feat: move csharp yasnippet functions to separate file --- init.el | 36 +++--------------------------------- lisp/csharp-yasnippet.el | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 lisp/csharp-yasnippet.el diff --git a/init.el b/init.el index 0671410e827ec78af09b103a3d5edb749108cb6f..40ce5f9853831247fb010b0c54cc00e6d32f2046 100644 --- a/init.el +++ b/init.el @@ -1432,39 +1432,10 @@ minibuffer, even without explicitly focusing it." :mode (("\\.cs\\'" . csharp-mode)) :config (my/indent-variable-mode-alist-add csharp-mode c-basic-offset) - (my/indent-variable-mode-alist-add csharp-ts-mode csharp-ts-mode-indent-offset) + (my/indent-variable-mode-alist-add csharp-ts-mode csharp-ts-mode-indent-offset)) - (defun csharp--get-csproj-in-directory (dir) - (car (directory-files dir - :mach-regexp ".*\\.csproj" - :count 1))) - - ;; Finds .csproj above current buffer directory, and returns path to the csproj - (defun csharp--find-csproj (dir) - (csharp--get-csproj-in-directory - (locate-dominating-file - dir #'csharp--get-csproj-in-directory))) - - (defun csharp--find-current-csproj () - (csharp--find-csproj buffer-file-name)) - - (defun csharp--extract-project-name () - (interactive) - (let ((csproj (csharp--find-current-csproj))) - (file-name-base csproj))) - - (defun csharp-file-path-to-namespace () - (interactive) - (let* ((root (file-name-directory (csharp--find-current-csproj))) - (base (file-name-nondirectory buffer-file-name)) - (project-name (csharp--extract-project-name)) - (subdirectory - (replace-regexp-in-string "/" "\." (substring buffer-file-name (length root) (* -1 (length base))) t t))) - (concat - project-name - (if (string= "" subdirectory) - "" - (concat "." (substring subdirectory 0 -1)))))) +(my-use-package csharp-yasnippet + :commands (csharp-file-path-to-namespace)) ;; Build solution ;; --debug / --release @@ -1478,7 +1449,6 @@ minibuffer, even without explicitly focusing it." ;; Run solution tests ;; Run csproj tests ;; Feeling lucky - run current file tests - ) (my-use-package sharper :ensure t diff --git a/lisp/csharp-yasnippet.el b/lisp/csharp-yasnippet.el new file mode 100644 index 0000000000000000000000000000000000000000..7ee1d454268f309bc894ef2b66a84db74e433d66 --- /dev/null +++ b/lisp/csharp-yasnippet.el @@ -0,0 +1,36 @@ +;;; csharp-yasnippet.el --- C# utility functions for yasnippet + +(provide 'csharp-yasnippet) + +(defun csharp--get-csproj-in-directory (dir) + (car (directory-files dir + :mach-regexp ".*\\.csproj" + :count 1))) + +(defun csharp--find-csproj (dir) + (csharp--get-csproj-in-directory + (locate-dominating-file + dir #'csharp--get-csproj-in-directory))) + +(defun csharp--find-current-csproj () + (csharp--find-csproj buffer-file-name)) + +(defun csharp--extract-project-name () + (interactive) + (let ((csproj (csharp--find-current-csproj))) + (file-name-base csproj))) + +(defun csharp-file-path-to-namespace () + (interactive) + (let* ((root (file-name-directory (csharp--find-current-csproj))) + (base (file-name-nondirectory buffer-file-name)) + (project-name (csharp--extract-project-name)) + (subdirectory + (replace-regexp-in-string "/" "\." (substring buffer-file-name (length root) (* -1 (length base))) t t))) + (concat + project-name + (if (string= "" subdirectory) + "" + (concat "." (substring subdirectory 0 -1)))))) + +;;; csharp-yasnippet.el ends here \ No newline at end of file