1 ;;; ironout.el --- a minor mode for using ironout
2 ;; Copyright (C) 2008 Ali Gholami Rudi
5 ;; * handle file names with spaces in ironout-find
6 ;; * interrupting ironout commands
9 "ironout, A C refactoring tool."
10 :link
'(url-link "http://ironout.berlios.de/")
13 (defcustom ironout-path
"ironout"
14 "The path to ironout executable.")
16 (defun ironout-rename ()
17 "Rename occurrences of a name."
19 (let ((buffer (get-buffer-create "*ironout-patch*"))
20 (newname (read-string "New Name: "))
21 (filename (buffer-file-name)))
22 (with-current-buffer buffer
23 (setq buffer-read-only
'nil
)
25 (let ((offset (int-to-string (- (+ (point-min) (point)) 2))))
26 (call-process ironout-path nil
'("*ironout-patch*" nil
) t
27 "rename" filename offset newname
))
28 (switch-to-buffer buffer
)
29 (goto-char (point-min))
31 (setq buffer-read-only
't
)
34 (defvar ironout-current-hit
0
35 "Points to current occurrence in *ironout-find* buffer.")
37 (defun ironout-find ()
38 "Find occurrences of a name."
40 (let ((buffer (get-buffer-create "*ironout-find*")))
41 (with-current-buffer buffer
42 (setq buffer-read-only
'nil
)
44 (let ((offset (int-to-string (- (+ (point-min) (point)) 2))))
45 (call-process ironout-path nil
'("*ironout-find*" nil
) t
46 "find" (buffer-file-name) offset
))
47 (with-current-buffer buffer
48 (goto-char (point-min))
49 (setq buffer-read-only
't
)
50 (local-set-key (kbd "RET") 'ironout-goto-hit
)
51 (local-set-key (kbd "C-j") 'ironout-goto-hit
)
52 (local-set-key (kbd "q") 'delete-window
)
54 (setq ironout-current-hit
0)
55 (setq next-error-function
'ironout-goto-next
)
56 (display-buffer buffer
)
59 (defun ironout-goto-next (arg reset
)
60 (switch-to-buffer-other-window "*ironout-find*" t
)
62 (goto-char (point-min)))
63 (setq ironout-current-hit
(+ ironout-current-hit arg
))
65 ((>= ironout-current-hit
(line-number-at-pos (point-max)))
66 (message "Moved past last hit!")
67 (setq ironout-current-hit
(line-number-at-pos (point-max))))
68 ((<= ironout-current-hit
0)
69 (message "Moved back before first hit!")
70 (setq ironout-current-hit
0))
72 (goto-line ironout-current-hit
)
74 (if (string-equal "*ironout-find*" (buffer-name))
77 (defun ironout-goto-hit ()
82 (let ((line (buffer-substring-no-properties (point) end
)))
83 (let ((tokens (split-string line
)))
85 (find-file-other-window (nth 0 tokens
))
86 (goto-char (+ (string-to-number (nth 1 tokens
)) 1))
90 (defvar ironout-local-keymap
(make-sparse-keymap))
92 (define-minor-mode ironout-mode
93 "ironout, a C refactoring tool!" nil
" Iron" ironout-local-keymap
96 (define-key ironout-local-keymap
(kbd "C-c i f") 'ironout-find
)
97 (define-key ironout-local-keymap
(kbd "C-c i r") 'ironout-rename
)
98 (add-hook 'c-mode-hook
'ironout-mode
)