~ruther/emacs.d

ref: c5125ba976fc06f13712f97a1fc36de469d1b8b3 emacs.d/lisp/csharp-yasnippet.el -rw-r--r-- 1.1 KiB
c5125ba9 — Rutherther feat: move csharp yasnippet functions to separate file a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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