[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simple useful function
From: |
Andrea Crotti |
Subject: |
Re: Simple useful function |
Date: |
Tue, 03 Aug 2010 17:11:18 +0200 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (darwin) |
If someone is interested now my "git" related functions are a bit
smarter
--8<---------------cut here---------------start------------->8---
(defun open-git-files ()
"Visit all the files in the current git project"
(interactive)
(dolist
(file (ls-git-files))
(message "Opening %s" file)
;; we have to keep the original position
(save-excursion (find-file file))))
(defun dired-git-files (directory)
"Open a dired buffer containing the local git files"
(interactive "D")
(cd directory)
(let ((files (ls-git-files)))
(if
(or
(< (length files) 200)
(yes-or-no-p (format "%d files, are you sure?" (length files))))
;; rename the buffer to something with a sense
(progn
(dired (ls-git-files))
(rename-buffer (concat "git-" (before-last (split-string directory
"/"))))))))
;; TODO: take the return code instead
(defun ls-git-files ()
(let
((result (shell-command-to-string (concat "git ls-files"))))
(if
(string-match "fatal" result)
nil
(split-string result))))
--8<---------------cut here---------------end--------------->8---
But this is probably even more cool
--8<---------------cut here---------------start------------->8---
(defun query-replace-in-git (from to)
"query replace regexp on the files given"
(interactive "sFrom: \nsTo: ")
(dired-git-files (pwd))
(dired-mark-files-regexp ".[ch]")
(dired-do-query-replace-regexp from to))
--8<---------------cut here---------------end--------------->8---
I use the above function and marking with git to replace in the whole
project in only one shot.
I should add maybe some other options for example for the files to mark
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Simple useful function,
Andrea Crotti <=