Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 240 lines (213 sloc) 9.083 kB
d6c1526 @tavisrudd lots of new helper functions
authored
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 (defun dss/display-syntax (syntax-type)
3 (eq syntax-type (syntax-ppss-context (syntax-ppss))))
4
5 (defun dss/in-syntax-p (syntax-type)
6 "This only answers if you're in a comment or string at the moment."
7 (eq syntax-type (syntax-ppss-context (syntax-ppss))))
8
9 (defun dss/in-string-p ()
10 (dss/in-syntax-p 'string))
11
12 (defun dss/in-comment-p ()
13 (dss/in-syntax-p 'comment))
14
15 (defun dss/blank-line-p ()
16 "Return non-nil iff current line is blank."
17 (save-excursion
18 (beginning-of-line)
19 (looking-at "\\s-*$")))
20
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 (defun dss/beginning-of-string ()
23 "Go to beginning of string around point.
24 Do nothing if not in string."
25 ;; from loveshack's python-beginning-of-string
26 (interactive)
693a846 @tavisrudd some reorg + tweaks to string motion funcs
authored
27 (if (and (not (dss/in-string-p))
28 (save-excursion
29 (backward-char)
30 (dss/in-string-p)))
31 (backward-char))
d6c1526 @tavisrudd lots of new helper functions
authored
32 (let ((state (syntax-ppss)))
33 (when (eq 'string (syntax-ppss-context state))
34 (goto-char (nth 8 state)))))
35
36 (defun dss/end-of-string ()
37 (interactive)
693a846 @tavisrudd some reorg + tweaks to string motion funcs
authored
38 (if (and (not (dss/in-string-p))
39 (save-excursion
40 (forward-char)
41 (dss/in-string-p)))
42 (forward-char))
d6c1526 @tavisrudd lots of new helper functions
authored
43 (if (dss/in-string-p)
44 (progn
45 (dss/beginning-of-string)
46 (forward-sexp))))
47
48 (defun dss/mark-string ()
49 (interactive)
50 (if (dss/in-string-p)
51 (progn
52 (dss/beginning-of-string)
53 (mark-sexp))))
54
55 (defun dss/forward-string (&optional backward)
56 (interactive)
57 (if (dss/in-string-p)
58 (dss/end-of-string))
59 (while (not (dss/in-string-p))
60 (if backward
61 (backward-char)
62 (forward-char))))
63
64 (defun dss/backward-string ()
65 (interactive)
66 (if (dss/in-string-p)
67 (dss/beginning-of-string))
68 (dss/forward-string t)
69 (dss/beginning-of-string)
70 (forward-char))
71
72 ;@@TR: I should add some similar functions for working with comments etc.
73
693a846 @tavisrudd some reorg + tweaks to string motion funcs
authored
74 (defun dss/out-sexp (&optional level forward syntax)
75 "Skip out of any nested brackets.
76 Skip forward if FORWARD is non-nil, else backward.
77 If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point.
78 Return non-nil if and only if skipping was done."
79 (interactive)
80 (if (dss/in-string-p)
81 (dss/beginning-of-string))
82 (progn
83 (let* ((depth (syntax-ppss-depth (or syntax (syntax-ppss))))
84 (level (or level depth))
85 (forward (if forward -1 1)))
86 (unless (zerop depth)
87 (if (> depth 0)
88 ;; Skip forward out of nested brackets.
89 (condition-case () ; beware invalid syntax
90 (progn (backward-up-list (* forward level)) t)
91 (error nil))
92 ;; Invalid syntax (too many closed brackets).
93 ;; Skip out of as many as possible.
94 (let (done)
95 (while (condition-case ()
96 (progn (backward-up-list forward)
97 (setq done t))
98 (error nil)))
99 done))))))
100
101 (defun dss/out-one-sexp (&optional forward)
102 (interactive)
103 (dss/out-sexp 1 forward))
104
105 (defun dss/out-one-sexp-forward ()
106 (interactive)
107 (dss/out-sexp 1 1))
108
d6c1526 @tavisrudd lots of new helper functions
authored
109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110 (defun dss/electric-pair ()
111 "If at end of line, insert character pair without surrounding spaces.
112 Otherwise, just insert the typed character."
113 (interactive)
114 ;(if (eolp) (let (parens-require-spaces) (insert-pair))
115 ; (self-insert-command 1)))
116 (if (or (dss/in-string-p)
117 (dss/in-comment-p))
118 (self-insert-command 1)
119 (let (parens-require-spaces)
120 (insert-pair))))
121
122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a16e888 @tavisrudd init import
authored
123 (require 'imenu)
124 (defun ido-imenu ()
125 "Update the imenu index and then use ido to select a symbol to navigate to.
126 Symbols matching the text at point are put first in the completion list.
127 Comes from http://github.com/technomancy/emacs-starter-kit/blob/master/starter-kit-defuns.el"
128 (interactive)
129 (imenu--make-index-alist)
130 (let ((name-and-pos '())
131 (symbol-names '()))
132 (flet ((addsymbols (symbol-list)
133 (when (listp symbol-list)
134 (dolist (symbol symbol-list)
135 (let ((name nil) (position nil))
136 (cond
137 ((and (listp symbol) (imenu--subalist-p symbol))
138 (addsymbols symbol))
139
140 ((listp symbol)
141 (setq name (car symbol))
142 (setq position (cdr symbol)))
143
144 ((stringp symbol)
145 (setq name symbol)
146 (setq position (get-text-property 1 'org-imenu-marker symbol))))
147
148 (unless (or (null position) (null name))
149 (add-to-list 'symbol-names name)
150 (add-to-list 'name-and-pos (cons name position))))))))
151 (addsymbols imenu--index-alist))
152 ;; If there are matching symbols at point, put them at the beginning of `symbol-names'.
153 (let ((symbol-at-point (thing-at-point 'symbol)))
154 (when symbol-at-point
155 (let* ((regexp (concat (regexp-quote symbol-at-point) "$"))
156 (matching-symbols (delq nil (mapcar (lambda (symbol)
157 (if (string-match regexp symbol) symbol))
158 symbol-names))))
159 (when matching-symbols
160 (sort matching-symbols (lambda (a b) (> (length a) (length b))))
161 (mapc (lambda (symbol) (setq symbol-names (cons symbol (delete symbol symbol-names))))
162 matching-symbols)))))
163 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
164 (position (cdr (assoc selected-symbol name-and-pos))))
165 (goto-char position))))
166
167 ;; ; http://nflath.com/2009/07/imenu/
168 ;; (require 'imenu)
169 ;; (setq imenu-auto-rescan t)
170 ;; (defun ido-goto-symbol ()
171 ;; "Will update the imenu index and then use ido to select a symbol to navigate to"
172 ;; (interactive)
173 ;; (imenu--make-index-alist)
174 ;; (let ((name-and-pos '())
175 ;; (symbol-names '()))
176 ;; (flet ((addsymbols (symbol-list)
177 ;; (when (listp symbol-list)
178 ;; (dolist (symbol symbol-list)
179 ;; (let ((name nil) (position nil))
180 ;; (cond
181 ;; ((and (listp symbol) (imenu--subalist-p symbol))
182 ;; (addsymbols symbol))
183 ;; ((listp symbol)
184 ;; (setq name (car symbol))
185 ;; (setq position (cdr symbol)))
186 ;; ((stringp symbol)
187 ;; (setq name symbol)
188 ;; (setq position (get-text-property 1 'org-imenu-marker symbol))))
189 ;; (unless (or (null position) (null name))
190 ;; (add-to-list 'symbol-names name)
191 ;; (add-to-list 'name-and-pos (cons name position))))))))
192 ;; (addsymbols imenu--index-alist))
193 ;; (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
194 ;; (position (cdr (assoc selected-symbol name-and-pos))))
195 ;; (if (markerp position)
196 ;; (goto-char position) (goto-char (overlay-start position))))))
197
198
7df2889 @tavisrudd column grid
authored
199 (defvar dss/major-column-face 'dss/major-column-face
200 "major column grid marker")
201 (defface dss/major-column-face '((t (:background "#484848")))
202 "major column grid marker"
203 :group 'faces)
204
205 (defvar dss/minor-column-face 'dss/minor-column-face
206 "minor column grid marker")
207 (defface dss/minor-column-face '((t (:background "#2c2c2c")))
208 "minor column grid marker"
209 :group 'faces)
210
211 (column-marker-create dss/column-marker-1 dss/minor-column-face)
212 (column-marker-create dss/column-marker-2 dss/major-column-face)
213 (column-marker-create dss/column-marker-3 dss/minor-column-face)
214 (column-marker-create dss/column-marker-4 dss/major-column-face)
215 (column-marker-create dss/column-marker-5 dss/minor-column-face)
216 (column-marker-create dss/column-marker-6 dss/major-column-face)
217 (column-marker-create dss/column-marker-7 dss/minor-column-face)
218 (column-marker-create dss/column-marker-8 dss/major-column-face)
219
220 (defun dss/column-grid ()
221 (interactive)
222 ;; col-highlight-face
223 (hl-line-mode -1)
224 (dss/column-marker-1 10)
225 (dss/column-marker-2 20)
226 (dss/column-marker-3 30)
227 (dss/column-marker-4 40)
228 (dss/column-marker-5 50)
229 (dss/column-marker-6 60)
230 (dss/column-marker-7 70)
231 (dss/column-marker-8 80))
232
233 (defun dss/column-grid-off ()
234 (interactive)
235 (dss/column-marker-1 -1)
236 (hl-line-mode t))
237
a16e888 @tavisrudd init import
authored
238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
239 (provide 'dss-codenav-helpers)
Something went wrong with that request. Please try again.