summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2015-06-25 05:53:10 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2015-06-25 15:04:04 (GMT)
commitd46e633c8660ab7c41ab26971025b1dfe858b888 (patch)
tree294aa793b653009e05a311f9b3d10525fe75976a
parent24af4244c8cb19cd982f860fd8b7e2e1d02da874 (diff)
downloaddotemacs-d46e633c8660ab7c41ab26971025b1dfe858b888.zip
dotemacs-d46e633c8660ab7c41ab26971025b1dfe858b888.tar.gz
dotemacs-d46e633c8660ab7c41ab26971025b1dfe858b888.tar.bz2
Add firestarter
-rw-r--r--lisp/ravi-init-function.el63
1 files changed, 63 insertions, 0 deletions
diff --git a/lisp/ravi-init-function.el b/lisp/ravi-init-function.el
index d1c8230..612286c 100644
--- a/lisp/ravi-init-function.el
+++ b/lisp/ravi-init-function.el
@@ -75,5 +75,68 @@ and file 'filename' will be opened and cursor set on line 'linenumber'"
(add-to-list 'guide-key/guide-key-sequence "C-x t"))
(ravi/setup-toggle-launcher-map)
+;; Start something going on saving a file
+(use-package firestarter
+ :config
+ (progn
+ (firestarter-mode 1))
+ :diminish firestarter-mode
+ :ensure t)
+
+(defun ravi/find-path-name-relative-to-project-root ()
+ "Find path of current buffer file relative to project root"
+ (interactive)
+ (let* ((root-dir (and (buffer-file-name)
+ (or (and (fboundp 'magit-get-top-dir) (magit-get-top-dir))
+ (and (fboundp 'vc-root-dir) (vc-root-dir))
+ (locate-dominating-file (buffer-file-name) ".git")
+ (locate-dominating-file (buffer-file-name) dir-locals-file))))
+ (relative-name (and root-dir
+ (file-relative-name (buffer-file-name) root-dir))))
+ relative-name))
+
+(defun ravi/apply-shell-command-relative-to-project (command-template)
+ "Apply shell command relative to project
+
+COMMAND-TEMPLATE should be a string with the following substitutions allowed:
+
+%p: full path to file name
+
+%r: path relative to project root
+
+%f: file name
+
+%N: unquoted relative path name (should be used extremely carefully)
+"
+ (interactive "sEnter command template: ")
+ (let* ((path (shell-quote-argument (or (buffer-file-name) "")))
+ (rel-name (ravi/find-path-name-relative-to-project-root))
+ (rel-path (shell-quote-argument (or rel-name "")))
+ (file (shell-quote-argument (file-name-nondirectory (or path ""))))
+ (cmd (and rel-name
+ (format-spec command-template
+ (format-spec-make ?p path ?r rel-path ?f file ?N rel-name)))))
+ (if cmd
+ (shell-command cmd)
+ (if (not (buffer-file-name))
+ (message "Not in a file buffer")
+ (message "Unable to find project root")))))
+
+(defvar ravi/shell-command-relative nil
+ "Variable to set in `dir-locals-file' for use with
+`ravi/apply-shell-command-relative-to-project-auto'. See
+`ravi/apply-shell-command-relative-to-project' for more
+details.")
+
+(defun ravi/apply-shell-command-relative-to-project-auto ()
+ "Apply shell command relative to project from variable
+`ravi/shell-command-relative'. See
+`ravi/apply-shell-command-relative-to-project' for more details.
+"
+ (interactive)
+ (when (and (stringp ravi/shell-command-relative)
+ (> (length ravi/shell-command-relative) 0))
+ (ravi/apply-shell-command-relative-to-project ravi/shell-command-relative)))
+
(provide 'ravi-init-function)
;;; ravi-init-function.el ends here