forked from sandbox/emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-functions.el
147 lines (134 loc) · 4.79 KB
/
my-functions.el
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(defun other-frame-1 () "does previous frame"
(interactive)
(other-frame -1))
(defun other-window-1 ()
"does previous window"
(interactive)
(other-window -1))
(defun asdfd ()
"sets my font to the thing I like on stanfords unix machines\nwhich is why it has such a ridiculous name"
(interactive)
(set-frame-font "-bitstream-Bitstream Vera Sans Mono-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1"))
(defun delete-until-pattern ()
"deletes until the given pattern"
(interactive)
(let ((regexp (read-from-minibuffer "Enter Pattern to delete until: ")))
(let ((beg (point))
(end (progn (search-forward-regexp regexp)
(search-backward-regexp regexp))))
(delete-region beg end))))
;;
;; taken from tassilo's blog
;;
(defun zap-to-string (arg str)
"Same as `zap-to-char' except that it zaps to the given string
instead of a char."
(interactive "p\nsZap to string: ")
(kill-region (point) (progn
(search-forward str nil nil arg)
(point))))
(defun zap-to-regexp (arg regexp)
"Same as `zap-to-char' except that it zaps to the given regexp
instead of a char."
(interactive "p\nsZap to regexp: ")
(kill-region (point) (progn
(re-search-forward regexp nil nil arg)
(point))))
(make-variable-frame-local 'my-frame-state)
(defun my-frame-maximize ()
"Maximize Emacs window in win32"
(interactive)
(modify-frame-parameters nil '((my-frame-state . t)))
(w32-send-sys-command ?\xf030))
(defun my-frame-restore ()
"Restore Emacs window in win32"
(interactive)
(modify-frame-parameters nil '((my-frame-state . nil)))
(w32-send-sys-command ?\xF120))
(defun my-frame-toggle ()
"Maximize/Restore Emacs frame based on `my-frame-state'"
(interactive)
(if my-frame-state
(my-frame-restore)
(my-frame-maximize)))
(global-set-key [(meta return)] 'my-frame-toggle)
(defun bash-term ()
(interactive)
(term "bash"))
(defun ido-goto-symbol (&optional symbol-list)
"Refresh imenu and jump to a place in the buffer using Ido."
(interactive)
(unless (featurep 'imenu)
(require 'imenu nil t))
(cond
((not symbol-list)
(let ((ido-mode ido-mode)
(ido-enable-flex-matching
(if (boundp 'ido-enable-flex-matching)
ido-enable-flex-matching t))
name-and-pos symbol-names position)
(unless ido-mode
(ido-mode 1)
(setq ido-enable-flex-matching t))
(while (progn
(imenu--cleanup)
(setq imenu--index-alist nil)
(ido-goto-symbol (imenu--make-index-alist))
(setq selected-symbol
(ido-completing-read "Symbol? " symbol-names))
(string= (car imenu--rescan-item) selected-symbol)))
(unless (and (boundp 'mark-active) mark-active)
(push-mark nil t nil))
(setq position (cdr (assoc selected-symbol name-and-pos)))
(cond
((overlayp position)
(goto-char (overlay-start position)))
(t
(goto-char position)))))
((listp symbol-list)
(dolist (symbol symbol-list)
(let (name position)
(cond
((and (listp symbol) (imenu--subalist-p symbol))
(ido-goto-symbol symbol))
((listp symbol)
(setq name (car symbol))
(setq position (cdr symbol)))
((stringp symbol)
(setq name symbol)
(setq position
(get-text-property 1 'org-imenu-marker symbol))))
(unless (or (null position) (null name)
(string= (car imenu--rescan-item) name))
(add-to-list 'symbol-names name)
(add-to-list 'name-and-pos (cons name position))))))))
;; (setq ido-execute-command-cache nil)
;; (defun ido-execute-command ()
;; (interactive)
;; (call-interactively
;; (intern
;; (ido-completing-read
;; "M-x "
;; (progn
;; (unless ido-execute-command-cache
;; (mapatoms (lambda (s)
;; (when (commandp s)
;; (setq ido-execute-command-cache
;; (cons (format "%S" s) ido-execute-command-cache))))))
;; ido-execute-command-cache)))))
;; (add-hook 'ido-setup-hook
;; (lambda ()
;; (setq ido-enable-flex-matching t)
;; (global-set-key "\M-x" 'ido-execute-command)))
;;
;; someone's blog on copy and pasting between mac and emacs
;;
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)