[PATCH] D23006: [clang-rename] add basic Emacs integration

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 1 02:52:58 PDT 2016

omtcyfz updated this revision to Diff 66292.
omtcyfz added a comment.

Update docs by adding information about Emacs integration.



Index: docs/clang-rename.rst
--- docs/clang-rename.rst
+++ docs/clang-rename.rst
@@ -28,7 +28,7 @@
 work with if you set up a compile command database for your project (for an
 example of how to do this see `How To Setup Tooling For LLVM
 <http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html>`_). You can also
-specify compilation options on the command line after ``--``:
+specify compilation options on the command line after `--`:
 .. code-block:: console
@@ -47,7 +47,7 @@
 renaming actions in the future.
 :program:`clang-rename` also aims to be easily integrated into popular text
-editors, such as Vim, and improve the workflow of users.
+editors, such as Vim and Emacs, and improve the workflow of users.
 Although a command line interface exists, it is highly recommended to use the
 text editor interface instead for better experience.
@@ -96,7 +96,22 @@
 happen before running the tool**.
 Once installed, you can point your cursor to symbols you want to rename, press
-``<leader>cr`` and print new desired name. The
-[``<leader> key``](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)#Map_leader)
+`<leader>cr` and print new desired name. The
+[`<leader> key`]
 is a reference to a specific key defined by the mapleader variable and is bound
 to backslash by default.
+clang-rename Emacs integration
+You can also use :program:`clang-rename` while using Emacs! To set up
+:program:`clang-rename` integration for Emacs see
+Once installed, you can point your cursor to symbols you want to rename, press
+`M-X`, print `clang-rename` and new desired name.
+Please note that **you have to save all buffers, in which the replacement will
+happen before running the tool**.
Index: clang-rename/tool/clang-rename.el
--- /dev/null
+++ clang-rename/tool/clang-rename.el
@@ -0,0 +1,46 @@
+;;; clang-rename.el --- Renames every occurrence of a symbol found at <offset>.
+;; Keywords: tools, c
+;;; Commentary:
+;; This package allows to filter code through clang-format to fix its formatting.
+;; clang-format is a tool that formats C/C++/Obj-C code according to a set of
+;; style options, see <http://clang.llvm.org/docs/ClangFormatStyleOptions.html>.
+;; Note that clang-format 3.4 or newer is required.
+;; To install clang-rename.el make sure the directory of this file is in your
+;; 'load-path' and add
+;;   (require 'clang-rename)
+;; to your .emacs configureation.
+;;; Code:
+(defvar clang-rename-binary "clang-rename")
+(defun clang-rename-upstream (new-name)
+  "Rename all instances of the symbol at the point using clang-rename"
+  (interactive "sEnter a new name: ")
+  (let (;; Emacs offset is 1-based.
+        (offset (- (point) 1))
+        (orig-buf (current-buffer))
+        (file-name (buffer-file-name)))
+    (let ((rename-command
+          (format "bash -f -c '%s -offset=%s -new-name=%s -i %s'"
+                               clang-rename-binary offset new-name file-name)))
+          (message (format "Running clang-rename command %s" rename-command))
+          ;; Run clang-rename via bash.
+          (shell-command rename-command)
+          ;; Reload buffer.
+          (interactive)
+          (revert-buffer t t)
+    )
+  )
+(provide 'clang-rename-upstream)
+;;; clang-rename.el ends here

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23006.66292.patch
Type: text/x-patch
Size: 3690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160801/4c468cf8/attachment-0001.bin>

More information about the cfe-commits mailing list