block: don't put spaces around :
[ironout.git] / ironout.el
blobfe292554321360c4c368adab6a601f05f98f23fe
1 ;;; ironout.el --- a minor mode for using ironout
2 ;; Copyright (C) 2008 Ali Gholami Rudi
4 ;;; TODO
5 ;; * handle file names with spaces in ironout-find
6 ;; * interrupting ironout commands
8 (defgroup ironout nil
9 "ironout, A C refactoring tool."
10 :link '(url-link "http://ironout.berlios.de/")
11 :prefix "ironout-")
13 (defcustom ironout-path "ironout"
14 "The path to ironout executable.")
16 (defun ironout-rename ()
17 "Rename occurrences of a name."
18 (interactive)
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)
24 (erase-buffer))
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))
30 (diff-mode)
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."
39 (interactive)
40 (let ((buffer (get-buffer-create "*ironout-find*")))
41 (with-current-buffer buffer
42 (setq buffer-read-only 'nil)
43 (erase-buffer))
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)
53 (recenter))
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)
61 (if reset
62 (goto-char (point-min)))
63 (setq ironout-current-hit (+ ironout-current-hit arg))
64 (cond
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))
71 ('t
72 (goto-line ironout-current-hit)
73 (ironout-goto-hit)))
74 (if (string-equal "*ironout-find*" (buffer-name))
75 (other-window -1)))
77 (defun ironout-goto-hit ()
78 (interactive)
79 (end-of-line)
80 (let ((end (point)))
81 (beginning-of-line)
82 (let ((line (buffer-substring-no-properties (point) end)))
83 (let ((tokens (split-string line)))
84 (recenter 0)
85 (find-file-other-window (nth 0 tokens))
86 (goto-char (+ (string-to-number (nth 1 tokens)) 1))
88 )))
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
94 :global nil)
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)
99 (provide 'ironout)