Skip to content

Commit f11fbfe

Browse files
committed
feat: include basic templates, headers and snippets in the project.
1 parent 6a3724b commit f11fbfe

File tree

36 files changed

+466
-10
lines changed

36 files changed

+466
-10
lines changed

headers/asl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Copyright (C) `(format-time-string "%Y")` `(user-full-name)`
2+
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.

headers/gpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (C) `(format-time-string "%Y")` `(user-full-name)`
2+
3+
This program is free software: you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation, version 3.
6+
7+
This program is distributed in the hope that it will be useful, but
8+
WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10+
General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program. If not, see <http://www.gnu.org/licenses/>.

idee-headers.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
;;
3333
;; Customization
3434
;;
35-
(defcustom idee-emacs-headers-dir "~/.emacs.d/headers" "The directory where header files are stored." :group 'idee :type 'string)
35+
(defconst idee-emacs-headers-dir (concat idee-resources-dir "headers") "The directory where header files are stored.")
3636

3737
;;
3838
;; State

idee-templates.el

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,21 @@
2626

2727
(require 'yasnippet)
2828

29+
(defconst idee-templates-dir
30+
(expand-file-name
31+
"templates"
32+
(file-name-directory
33+
;; Copied from ‘yasnippet-snippets’ that copied from ‘f-this-file’ from f.el.
34+
(cond
35+
(load-in-progress load-file-name)
36+
((and (boundp 'byte-compile-current-file) byte-compile-current-file)
37+
byte-compile-current-file)
38+
(:else (buffer-file-name))))))
39+
2940
;;
3041
;; State
3142
;;
32-
(defcustom idee-emacs-templates-dir "~/.config/emacs/templates" "The directory where template files are stored." :group 'idee :type 'string)
43+
(defconst idee-emacs-templates-dir (concat idee-resources-dir "templates") "The directory where template files are stored.")
3344

3445
(defvar idee-type-modes-alist '() "Association list for extension to mode.")
3546
(setq idee-type-modes-alist '(

idee-utils.el

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,25 @@
116116
(concat (capitalize first) rest-str))))
117117

118118
;;; Misc Functions
119-
(defun idee-screenshot ()
120-
"Get a screenshot."
121-
(interactive)
122-
(shell-command "scrot -s '/home/iocanel/Photos/screenshots/%Y-%m-%d_%H:%M:%S_$wx$h.png'"))
123-
124-
(global-set-key (kbd "C-c i s") 'idee-screenshot)
125-
119+
(defun idee-screenshot ()
120+
"Get a screenshot."
121+
(interactive)
122+
(shell-command "scrot -s '/home/iocanel/Photos/screenshots/%Y-%m-%d_%H:%M:%S_$wx$h.png'"))
123+
124+
(global-set-key (kbd "C-c i s") 'idee-screenshot)
125+
126+
127+
(defun idee--git-checkout (repo target &optional dirs)
128+
"Checkout a git REPO into the TARGET dir. Optionally only checkout one or more DIRS."
129+
(make-directory target t)
130+
(setq default-directory (file-name-as-directory target))
131+
(call-process-shell-command "git init")
132+
(call-process-shell-command (format "git remote add -f origin %s" repo))
133+
(if dirs
134+
(progn
135+
(call-process-shell-command "git config core.sparseCheckout true")
136+
(mapc (lambda (x) (call-process-shell-command (format "echo '%s' >> .git/info/sparse-checkout" x))) dirs)))
137+
(call-process-shell-command "git checkout master"))
138+
126139
(provide 'idee-utils)
127140
;;; idee-utils.el ends here

idee-vars.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
;;; Commentary:
2424

2525
;;; Code:
26-
26+
(defcustom idee-resources-dir (locate-user-emacs-file "idee") "The directory where idee files are stored." :group 'idee :type 'string)
2727
(defcustom idee-project-conf-dir ".idee" "The directory where idee configuration files are stored." :group 'idee :type 'string)
2828

2929
;; Tabs and indentation

idee.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@
2828
(require 'idee-navigation)
2929
(require 'idee-projects)
3030
(require 'idee-templates)
31+
(require 'idee-vars)
32+
(require 'idee-utils)
3133

34+
(defcustom idee-repo-url "idee" "The repository url of the idee project." :group 'idee :type 'string)
3235

36+
(defun idee-resources-init ()
37+
"Initialize idee resources."
38+
(idee--git-checkout idee-repo-url idee-resources-dir '("headers" "templates" "snippets")))
39+
40+
(idee-resources-init)
3341
(provide 'idee)
3442
;;; idee.el ends here

snippets/java-mode/cons

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- mode: snippet -*-
2+
# name: constant string
3+
# key: cons
4+
# --
5+
private static final String ${1:$(upcase (replace-regexp-in-string "[^a-zA-z0-9]+" "_" yas-text))} = "${1:constant}";
6+
$0

snippets/java-mode/g

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- mode: snippet -*-
2+
# name: getter
3+
# key: g
4+
# --
5+
6+
public ${1:String} get${2:$(capitalize yas-text)}() {
7+
return this.${2:field};
8+
}
9+
$0

snippets/java-mode/gs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- mode: snippet -*-
2+
# name: getter & setter
3+
# key: gs
4+
# --
5+
6+
public ${1:String} get${2:$(idee-capitalize-first yas-text)}() {
7+
return this.${2:field};
8+
}
9+
10+
public void set${2:$(idee-capitalize-first yas-text)}($1 $2) {
11+
this.$2=$2;
12+
}
13+
$0

0 commit comments

Comments
 (0)