~ruther/emacs.d

c5125ba976fc06f13712f97a1fc36de469d1b8b3 — Rutherther a month ago 72e2dbc
feat: move csharp yasnippet functions to separate file
2 files changed, 39 insertions(+), 33 deletions(-)

M init.el
A lisp/csharp-yasnippet.el
M init.el => init.el +3 -33
@@ 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

A lisp/csharp-yasnippet.el => lisp/csharp-yasnippet.el +36 -0
@@ 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