summaryrefslogtreecommitdiffstats
path: root/lisp/ravi-init-function.el
blob: da87931d62e6c37f69b4294d0a25ea8635c6ce6f (plain)
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
;;; 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
(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 ()
  (define-prefix-command 'ravi/toggle-launcher-map)
  (bind-key "t" 'ravi/toggle-launcher-map ctl-x-map)

  ;; Toggles
  (bind-key "c" 'column-number-mode ravi/toggle-launcher-map)
  (bind-key "e" 'toggle-debug-on-error ravi/toggle-launcher-map)
  (bind-key "f" 'auto-fill-mode ravi/toggle-launcher-map)
  (bind-key "l" 'toggle-truncate-lines ravi/toggle-launcher-map)
  (bind-key "q" 'toggle-debug-on-quit ravi/toggle-launcher-map)
  ;; Generalized version of `read-only-mode'.
  (bind-key "r" 'dired-toggle-read-only ravi/toggle-launcher-map)
  (autoload 'dired-toggle-read-only "dired" nil t)
  (bind-key "w" 'whitespace-mode ravi/toggle-launcher-map)

  ;; Launchers
  (bind-key "P" 'package-list-packages ravi/toggle-launcher-map)
  (bind-key "p" 'proced ravi/toggle-launcher-map)
  (bind-key "d" 'ediff-buffers ravi/toggle-launcher-map)
  (bind-key "F" 'find-dired ravi/toggle-launcher-map)
  (add-to-list 'guide-key/guide-key-sequence "C-x t"))
(ravi/setup-toggle-launcher-map)

(provide 'ravi-init-function)
;;; ravi-init-function.el ends here