forked from alienrobotwizard/emacs-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrflip-defuns.el
138 lines (123 loc) · 5.38 KB
/
mrflip-defuns.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
;;
;; ------------------ Handy functions --------------
;;
(defun fixnewlines () "Turn ^M into ^J." (interactive) (replace-string "\C-M" "\C-j"))
(defun set-tab-width-2 () "Sets tab width to 2" (interactive) (setq tab-width 2) (font-lock-and-redraw))
(defun set-tab-width-4 () "Sets tab width to 4" (interactive) (setq tab-width 4) (font-lock-and-redraw))
(defun set-tab-width-8 () "Sets tab width to 8" (interactive) (setq tab-width 8) (font-lock-and-redraw))
(defun Buffer-menu-sort-by-path () "Sort buffer menu by pathname" (interactive) (Buffer-menu-sort 5))
(defun font-lock-and-redraw () "Force a font-lock-fontify-buffer and then do the redraw" (interactive) (font-lock-fontify-buffer) (recenter) )
;; (defun imw-find-file ()
;; "Prompt for a `name' and scan the `lib' and `spec' directories in the IMW root directory ($IMW_ROOT) and open the first file matching `name.rb'"
;; (interactive)
;; (let* ((name (read-from-minibuffer "IMW File: "))
;; (files (split-string
;; (concat
;; (shell-command-to-string "find $IMW_ROOT/lib")
;; (shell-command-to-string "find $IMW_ROOT/spec"))
;; "\n")))
;; (find-file (catch 'break
;; (dolist (file files)
;; (if (string-match (concat "/" name "\\.rb$") file)
;; (throw 'break file)))))))
;; (define-key ruby-mode-map "\C-cf" 'imw-find-file)
(defun count-words-region (beginning end)
"Print number of words in the region."
(interactive "r")
(message "Counting words in region ... ")
;;; 1. Set up appropriate conditions.
(save-excursion
(let ((count 0)) (goto-char beginning)
;;; 2. Run the while loop.
(while (and (< (point) end) (re-search-forward "\\w+\\W*" end t)) (setq count (1+ count)))
;;; 3. Send a message to the user.
(cond ((zerop count) (message "The region does NOT have any words."))
((= 1 count) (message "The region has 1 word."))
(t (message "The region has %d words." count))))))
;;; Bug: kills line and newline. o wells
(defun delete-line () "deletes the line forward"
(interactive "")
(save-excursion
(delete-region (point) (progn (forward-visible-line 1) (point))) ))
(defun delete-next-word () "deletes (without copying) the next word"
(interactive "")
(save-excursion
(delete-region (point) (progn (forward-word) (point))) ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Indentation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; http://www.jwz.org/doc/tabs-vs-spaces.html
;; In Emacs, to set the mod-N indentation used when you hit the TAB
;; key, do this:
;; (setq c-basic-indent 2)
;; To cause the TAB file-character to be interpreted as mod-N
;; indentation, do this:
;; (setq tab-width 4)
;; To cause TAB characters to not be used in the file for compression,
;; and for only spaces to be used, do this:
(setq indent-tabs-mode nil)
(defun indent-buffer ()
"Indent the current buffer."
(interactive)
(indent-region (point-min) (point-max) nil)
)
(defun right-justify-line ()
"Justify the current line to the right"
(interactive)
(justify-current-line 'right)
)
(defun indent-line-or-region-rigidly (b e n) "indent-rigidly by arg tab-widths"
(interactive "r\np")
(save-excursion
(let (deactivate-mark)
(if (or (= b e) (not mark-active))
(progn
(end-of-line)
(let ((eol (point)))
(beginning-of-line)
(indent-rigidly (point) eol (* tab-width n))))
(indent-rigidly b e (* tab-width n))))))
(defun unindent-line-or-region-rigidly (b e n) "(un)indent-rigidly by -arg tab-widths"
(interactive "r\np")
(indent-line-or-region-rigidly b e (* -1 n)))
;;
;;
;; -- Make Flymake sane in Tramp --
;;
(defun flymake-create-temp-intemp (file-name prefix)
"Return file name in temporary directory for checking FILE-NAME.
This is a replacement for `flymake-create-temp-inplace'. The
difference is that it gives a file name in
`temporary-file-directory' instead of the same directory as
FILE-NAME.
For the use of PREFIX see that function.
Note that not making the temporary file in another directory
\(like here) will not if the file you are checking depends on
relative paths to other files \(for the type of checks flymake
makes)."
(unless (stringp file-name)
(error "Invalid file-name"))
(or prefix
(setq prefix "flymake"))
(let* ((name (concat
(file-name-nondirectory
(file-name-sans-extension file-name))
"_" prefix))
(ext (concat "." (file-name-extension file-name)))
(temp-name (make-temp-file name nil ext))
)
(flymake-log 3 "create-temp-intemp: file=%s temp=%s" file-name temp-name)
temp-name))
(defun flymake-ruby-init ()
(condition-case er
(let* ((temp-file (flymake-init-create-temp-buffer-copy
;; 'flymake-create-temp-inplace
'flymake-create-temp-intemp
))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list rails-ruby-command (list "-c" local-file)))
('error ())))
(provide 'mrflip-defuns)