blob: aa7ff49f1bdb28ae8bd44f2f55a0bc7a0073a6cc [file] [log] [blame]
Kirill Bobyrevaa484502016-08-02 08:51:26 +00001;;; clang-rename.el --- Renames every occurrence of a symbol found at <offset>.
2
3;; Keywords: tools, c
4
5;;; Commentary:
6
7;; To install clang-rename.el make sure the directory of this file is in your
8;; 'load-path' and add
9;;
10;; (require 'clang-rename)
11;;
12;; to your .emacs configuration.
13
14;;; Code:
15
16(defcustom clang-rename-binary "clang-rename"
17 "Path to clang-rename executable."
18 :type 'hook
19 :options '(turn-on-auto-fill flyspell-mode)
20 :group 'wp)
21
22(defun clang-rename (new-name)
23 "Rename all instances of the symbol at the point using clang-rename"
24 (interactive "sEnter a new name: ")
25 (let (;; Emacs offset is 1-based.
26 (offset (- (point) 1))
27 (orig-buf (current-buffer))
28 (file-name (buffer-file-name)))
29
30 (let ((rename-command
31 (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
32 clang-rename-binary offset new-name file-name)))
33 (message (format "Running clang-rename command %s" rename-command))
34 ;; Run clang-rename via bash.
35 (shell-command rename-command)
36 ;; Reload buffer.
Kirill Bobyrevef2ee1fd62016-08-02 18:23:08 +000037 (revert-buffer t t)
Kirill Bobyrevaa484502016-08-02 08:51:26 +000038 )
39 )
40)
41
42(provide 'clang-rename)
43
44;;; clang-rename.el ends here