-
Notifications
You must be signed in to change notification settings - Fork 3
/
idee-headers.el
95 lines (74 loc) · 3.05 KB
/
idee-headers.el
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;; idee-headers.el --- Emacs IDE Header support.
;; Copyright (C) 2018 Ioannis Canellos
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;; http://www.apache.org/licenses/LICENSE-2.0
;;Unless required by applicable law or agreed to in writing, software
;;distributed under the License is distributed on an "AS IS" BASIS,
;;WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;See the License for the specific language governing permissions and
;;limitations under the License.
;; Author: Ioannis Canellos
;;; Commentary:
;;; Code:
(require 'idee-projects)
(require 'idee-vars)
(require 'idee-comments)
(require 'idee-vars)
;;
;; Customization
;;
(defvar idee/header-selected-kind nil "The kind of header currently selcted.")
(defvar idee/header "" "The header to add to files.")
;;
;; Functions
;;
(defun idee/header-detect ()
"Detect and set the value of idee/header-current, if exists."
(let ((h (idee/header-of-project)))
(if h
(setq idee/header-current h))))
(defun idee/header-of-project ()
"Read the header from header.txt."
(let ((root-dir-header (concat (idee/project-root-dir (buffer-file-name)) "header.txt"))
(idee/dir-header (concat (idee/project-root-dir (buffer-file-name)) (file-name-as-directory idee/project-conf-dir) "header.txt")))
(cond ((file-exists-p root-dir-header) (idee/read-and-eval-template root-dir-header))
((file-exists-p idee/dir-header) (idee/read-and-eval-template idee/dir-header))
(t nil))))
(defun idee/header-of-buffer ()
"Return the header commented for the current buffer style."
(idee/header-detect)
(idee/comment idee/header-current (file-name-extension (buffer-file-name (current-buffer)))))
;;;###autoload
(defun idee/header-select ()
"Select a header for the project from the existing selection of headers."
(interactive)
(let* ((headers (directory-files idee/emacs-headers-dir))
(kind (projectile-completing-read "Select header:" headers)))
(setq idee/header-selected-kind kind)
(setq idee/header-current (idee/read-and-eval-template (concat (file-name-as-directory idee/emacs-headers-dir) kind)))))
;;;###autoload
(defun idee/header-apply-to-buffer ()
"Apply the selected header to the current buffer."
(interactive)
(save-excursion
(goto-char (point-min))
(idee/comment-remove-at-point)
(insert (idee/header-of-buffer))))
;;;###autoload
(defun idee/header-apply-to-project ()
"Recursively visit all project files nad apply the selected header."
(interactive)
(idee/visit-project-files 'idee/header-apply-to-file))
;;;###autoload
(defun idee/header-apply-to-file (f)
"Apply the selected header to the specified file F."
(find-file f)
(idee/header-apply-to-buffer)
(write-file f))
(defun idee/header-source-dir ()
"Find the headers source directory."
(concat (file-name-as-directory (idee/source-dir)) "headers"))
(provide 'idee-headers)
;;; idee-headers.el ends here