summaryrefslogtreecommitdiffstats
path: root/lisp/ravi-init-function.el
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2015-10-23 18:57:59 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2015-10-23 18:57:59 (GMT)
commitcd1924466152177ea06b17c843f256463c1b91b8 (patch)
treeaf90afe028e5e392f242a3ea36302aafe1c1769d /lisp/ravi-init-function.el
parent5561df232cfa49822f322196d98170f95aa1139e (diff)
parent74c319ef12dd3130f6afc17abc59404b59d601d1 (diff)
downloaddotemacs-cd1924466152177ea06b17c843f256463c1b91b8.zip
dotemacs-cd1924466152177ea06b17c843f256463c1b91b8.tar.gz
dotemacs-cd1924466152177ea06b17c843f256463c1b91b8.tar.bz2
Merge branch 'master' into rtags-attempt
* master: (139 commits) Add pdf-tools as a nicer replacement for doc-view Add pdf-tools submodule Fix maildir data with correct path Add desktop notifications for email Potential use for modes without repls Attach files more easily in mu Update to newest version of mu Please remove tooltips after a while, please ace-window gets confused when tooltips are present Sometimes the dispatch list does come in handy Pre-populate searches Succumb to muscle memory of control keys Remove ropemacs due to disuse Do not let company-quickhelp steal a global key Manage word navigation Use proper helm function to replace completing-read Electric operators on python mode Use which-key in preference to guide-key Navigate easier Simplify config with magit 2.1.0 ...
Diffstat (limited to 'lisp/ravi-init-function.el')
-rw-r--r--lisp/ravi-init-function.el144
1 files changed, 144 insertions, 0 deletions
diff --git a/lisp/ravi-init-function.el b/lisp/ravi-init-function.el
new file mode 100644
index 0000000..673031a
--- /dev/null
+++ b/lisp/ravi-init-function.el
@@ -0,0 +1,144 @@
+;;; ravi-init-function.el --- functionality
+
+;; Copyright (C) 2013
+
+;; Author: <ravi@nero.lan>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Enable functionality
+
+;;; Code:
+
+;; Enable emacs functionality that is disabled by default
+(setq disabled-command-function nil)
+;(setq enable-recursive-minibuffers t)
+
+;; Use emacsclient from other programs
+(require 'server)
+(unless (server-running-p) (server-start))
+
+;; Stolen from prelude
+(defadvice server-visit-files (before parse-numbers-in-lines (files proc &optional nowait) activate)
+ "Open file with emacsclient with cursors positioned on requested line.
+Most of console-based utilities prints filename in format
+'filename:linenumber'. So you may wish to open filename in that format.
+Just call:
+emacsclient filename:linenumber
+and file 'filename' will be opened and cursor set on line 'linenumber'"
+ (ad-set-arg 0
+ (mapcar (lambda (fn)
+ (let ((name (car fn)))
+ (if (string-match "^\\(.*?\\):\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?$" name)
+ (cons
+ (match-string 1 name)
+ (cons (string-to-number (match-string 2 name))
+ (string-to-number (or (match-string 3 name) ""))))
+ fn))) files)))
+
+;; Combined launcher and toggle-maps
+(defun ravi/setup-toggle-launcher-map ()
+ (bind-keys :map ctl-x-map
+ :prefix-map ravi/setup-toggle-launcher-map
+ :prefix-docstring "Launcher/toggle map"
+ :prefix "t"
+
+ ;; Toggles
+ ("c" . column-number-mode)
+ ("e" . toggle-debug-on-error)
+ ("f" . auto-fill-mode)
+ ("l" . toggle-truncate-lines)
+ ("q" . toggle-debug-on-quit)
+ ;; Generalized version of `read-only-mode'.
+ ("r" . dired-toggle-read-only)
+ ("w" . whitespace-mode)
+
+ ;; Launchers
+ ("P" . package-list-packages)
+ ("p" . proced)
+ ("d" . ediff-buffers)
+ ("F" . find-dired))
+ (autoload 'dired-toggle-read-only "dired" nil t)
+ ;; (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