diff options
Diffstat (limited to 'lib/skels/jao-skel.el')
-rw-r--r-- | lib/skels/jao-skel.el | 118 |
1 files changed, 32 insertions, 86 deletions
diff --git a/lib/skels/jao-skel.el b/lib/skels/jao-skel.el index 859810d..9bd402d 100644 --- a/lib/skels/jao-skel.el +++ b/lib/skels/jao-skel.el @@ -29,129 +29,75 @@ (require 'skeleton) (require 'autoinsert) -(defvar jao-company-name nil +(defvar jao-skel-company-name nil "Company name used in copyright notice") -(defvar jao-copyright-file ".copyright" +(defvar jao-skel-copyright-file ".copyright" "Basename of the raw (uncommented) copyright file") -(defvar jao-skels-default-scm nil - "Default SCM system") +(defun jao-skel--prefix (pref) (or pref (concat comment-start " "))) +(defun jao-skel--suffix (suff) (or suff (concat " " comment-end))) -(defun jao-prefix (pref) (or pref (concat comment-start " "))) -(defun jao-suffix (suff) (or suff (concat " " comment-end))) - -(defun jao-copyright-line (prefix &optional suffix omit-cpy) +(defun jao-skel-copyright-line (prefix &optional suffix omit-cpy) "Create a brief copyright notice with given PREFIX and SUFFIX" - (concat (jao-prefix prefix) + (concat (jao-skel--prefix prefix) (if omit-cpy "" "Copyright ") "(c) " (format-time-string "%Y") " " - (or jao-company-name (user-full-name)) - (jao-suffix suffix) "\n")) + (or jao-skel-company-name (user-full-name)) + (jao-skel--suffix suffix) "\n")) -(defun jao-date-line (prefix &optional suffix) +(defun jao-skel-date-line (prefix &optional suffix) "Create a start date line" - (concat (jao-prefix prefix) + (concat (jao-skel--prefix prefix) "Start date: " (format-time-string "%a %b %d, %Y %H:%M") - (jao-suffix suffix) "\n")) + (jao-skel--suffix suffix) "\n")) -(defun jao-author-line (prefix &optional suffix) +(defun jao-skel-author-line (prefix &optional suffix) "Create an author date line" - (concat (jao-prefix prefix) + (concat (jao-skel--prefix prefix) "Author: " (user-full-name) " <" user-mail-address "> " - (jao-suffix suffix) "\n")) - -(defun jao-cvs-line (prefix &optional suffix) - "Create a CVS ID line" - (concat (jao-prefix prefix) "$" "Id$" (jao-suffix suffix) "\n")) - -(defun jao-svn-line (prefix &optional suffix) - "Create a SVN ID line" - (concat (jao-prefix prefix) "X-SVN: $" "Id$" (jao-suffix suffix) "\n")) - -(defun jao-arch-line (&optional prefix suffix) - "Create an arch-tag line" - (let ((uuid (shell-command-to-string "uuidgen"))) - (concat (jao-prefix prefix) "arch-tag: " uuid (jao-suffix suffix) "\n"))) - -(defun jao-insert-arch-line () - (interactive) - (insert (jao-arch-line))) - -(defun jao-scm-line (prefix &optional suffix) - "Create an scm line" - (let* ((formats '(("arch" . jao-arch-line) - ("svn" . jao-svn-line) - ("cvs" . jao-cvs-line) - ("none" . (lambda (p f) "")))) - (names (mapcar 'car formats)) - (prompt (concat "SCM (" (mapconcat 'identity names ", ") "): ")) - (sel (or jao-skels-default-scm - (completing-read prompt formats nil 1))) - (fun (cdr (assoc sel formats)))) - (when fun (concat (funcall fun prefix suffix))))) - -(defun jao-c&co-line (&optional prefix suffix) - (concat (jao-scm-line prefix suffix) "\n" - (jao-co-line prefix suffix))) - -(defun jao-co-line (&optional prefix suffix) - (concat (jao-copyright-line prefix suffix) "\n" - (jao-author-line prefix suffix) - (jao-date-line prefix suffix))) - -;; aux functions --------------------------------------------------------- -(defun jao-basename () - "Get buffer file name without dir nor extension" - (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))) + (jao-skel--suffix suffix) "\n")) -(defun jao-basedir () - "Base directory" - (file-name-nondirectory - (substring (file-name-directory (buffer-file-name)) 0 -1))) +(defun jao-skel-copyright-lines (&optional prefix suffix) + (concat (jao-skel-copyright-line prefix suffix) "\n" + (jao-skel-author-line prefix suffix) + (jao-skel-date-line prefix suffix))) -(defun jao-dir-level (l) - (let ((elems (split-string - (file-name-sans-extension (buffer-file-name)) "/"))) - (mapconcat 'identity (nthcdr (- (length elems) (+ 1 l)) elems) "/"))) +(defun jao-skel-basename () + "Get buffer file name without dir nor extension" + (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))) -(defun jao-extension () +(defun jao-skel-extension () "Find the extension of the currently visited file" (let ((elems (split-string (file-name-nondirectory (buffer-file-name)) "\\."))) (nth (- (length elems) 1) elems))) -(defun jao-other-file-name (ext1 ext2) - "Find the complimentary file name of header/source file" - (let ((extension (jao-extension)) - (basename (jao-basename))) - (if (string= extension ext1) (concat basename "." ext2) - (concat basename "." ext1)))) - -(defun jao-insert-commented-file (file-name) +(defun jao-skel--insert-commented-file (file-name) (let* ((start (point)) (end (+ start (cadr (insert-file-contents file-name))))) (goto-char end) (comment-region start (point)))) -(defun jao-insert-copyright-file () - (let ((dir (locate-dominating-file (buffer-file-name) jao-copyright-file))) +(defun jao-skel-insert-license () + (let ((dir (locate-dominating-file (buffer-file-name) jao-skel-copyright-file))) (when dir - (let ((file (expand-file-name jao-copyright-file dir))) + (let ((file (expand-file-name jao-skel-copyright-file dir))) (when (file-exists-p file) - (jao-insert-commented-file file)))))) + (jao-skel--insert-commented-file file)))))) -(defun jao-provide-skel (regexp skel) +(defun jao-skel-install (regexp skel) (let ((ex (assoc regexp auto-insert-alist))) (if ex (setf (cdr ex) skel) (add-to-list 'auto-insert-alist (cons regexp skel))))) -(defsubst jao-skel-provide (lst) - (mapc (lambda (x) (apply #'jao-provide-skel x)) lst)) +(defsubst jao-skel-install* (lst) + (mapc (lambda (x) (apply #'jao-skel-install x)) lst)) (setq auto-insert t) (add-hook 'find-file-hooks 'auto-insert) -(setq auto-insert-directory "~/.autoinsert/") + +(setq auto-insert-directory "~/.emacs.d/autoinsert/") (setq auto-insert-query t) (provide 'jao-skel) |