Kirill Bobyrev | aa48450 | 2016-08-02 08:51:26 +0000 | [diff] [blame^] | 1 | ;;; 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. |
| 37 | (interactive) |
| 38 | (revert-buffer t t) |
| 39 | ) |
| 40 | ) |
| 41 | ) |
| 42 | |
| 43 | (provide 'clang-rename) |
| 44 | |
| 45 | ;;; clang-rename.el ends here |