Emacs users: hg-tools-grep
Hark fellow Emacsers. All you unenlightened heathens can stop reading now. A few years ago, my colleague Jono Lange wrote probably the best little chunk of Emacs lisp ever. `M-x bzr-tools-grep` lets you easily search a Bazaar repository for a case-sensitive string, providing you with a nice *grep* buffer which you can scroll through. When you find a code sample you want to look at, C-c C-c visits the file and plops you right at the matching line. You *only* grep through files under version control, so you get to ignore generated files, and compilation artifacts, etc. Of course, this doesn't help you for working on the Python code base, because Mercurial. I finally whipped up this straight up rip of Jono's code to work with hg. I'm actually embarrassed to put a copyright on this thing, and would happily just donate it to Jono, drop it in Python's Misc directory, or slip it like a lump of coal into the xmas stocking of whoever wants to "maintain" it for the next 20 years. But anyway, it's already proven enormously helpful to me, so here it is. Cheers, -Barry P.S. Who wants to abuse Jono and Matthew's copyright again and provide a <shudder> git version? ;; Copyright (c) 2012 Barry A. Warsaw ;; ;; Permission is hereby granted, free of charge, to any person obtaining ;; a copy of this software and associated documentation files (the ;; "Software"), to deal in the Software without restriction, including ;; without limitation the rights to use, copy, modify, merge, publish, ;; distribute, sublicense, and/or sell copies of the Software, and to ;; permit persons to whom the Software is furnished to do so, subject to ;; the following conditions: ;; ;; The above copyright notice and this permission notice shall be ;; included in all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ;; This code is based on bzr-tools.el ;; Copyright (c) 2008-2009 Jonathan Lange, Matthew Lefkowitz (provide 'hg-tools) (defconst hg-tools-grep-command "hg locate --print0 | xargs -0 grep -In %s" "The command used for grepping files using hg. See `hg-tools-grep'.") ;; Run 'code' at the root of the branch which dirname is in. (defmacro hg-tools-at-branch-root (dirname &rest code) `(let ((default-directory (locate-dominating-file (expand-file-name ,dirname) ".hg"))) ,@code)) (defun hg-tools-grep (expression dirname) "Search a branch for `expression'. If there's a C-u prefix, prompt for `dirname'." (interactive (let* ((string (read-string "Search for: ")) (dir (if (null current-prefix-arg) default-directory (read-directory-name (format "Search for %s in: " string))))) (list string dir))) (hg-tools-at-branch-root dirname (grep-find (format hg-tools-grep-command (shell-quote-argument expression)))))
Am 08.12.2012 22:51, schrieb Barry Warsaw:
Hark fellow Emacsers. All you unenlightened heathens can stop reading now.
A few years ago, my colleague Jono Lange wrote probably the best little chunk of Emacs lisp ever. `M-x bzr-tools-grep` lets you easily search a Bazaar repository for a case-sensitive string, providing you with a nice *grep* buffer which you can scroll through. When you find a code sample you want to look at, C-c C-c visits the file and plops you right at the matching line. You *only* grep through files under version control, so you get to ignore generated files, and compilation artifacts, etc.
Of course, this doesn't help you for working on the Python code base, because Mercurial. I finally whipped up this straight up rip of Jono's code to work with hg. I'm actually embarrassed to put a copyright on this thing, and would happily just donate it to Jono, drop it in Python's Misc directory, or slip it like a lump of coal into the xmas stocking of whoever wants to "maintain" it for the next 20 years.
But anyway, it's already proven enormously helpful to me, so here it is.
Thanks, I'll definitely use this! Georg
P.S. Who wants to abuse Jono and Matthew's copyright again and provide a <shudder> git version?
Oh, I do! I also feel weird about adding a copyright to this, but how will other people feel comfortable using it if I don't? Also I put it in github, in case people want to fix it: https://github.com/quodlibetor/git-tools.el ;; Copyright (c) 2012 Brandon W Maister ;; ;; Permission is hereby granted, free of charge, to any person obtaining ;; a copy of this software and associated documentation files (the ;; "Software"), to deal in the Software without restriction, including ;; without limitation the rights to use, copy, modify, merge, publish, ;; distribute, sublicense, and/or sell copies of the Software, and to ;; permit persons to whom the Software is furnished to do so, subject to ;; the following conditions: ;; ;; The above copyright notice and this permission notice shall be ;; included in all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ;; This code is based on hg-tools.el, which in turn is based on bzr-tools.el ;; Copyright (c) 2008-2012 Jonathan Lange, Matthew Lefkowitz, Barry A. Warsaw (provide 'git-tools) (defconst git-tools-grep-command "git ls-files -z | xargs -0 grep -In %s" "The command used for grepping files using git. See `git-tools-grep'.") ;; Run 'code' at the root of the branch which dirname is in. (defmacro git-tools-at-branch-root (dirname &rest code) `(let ((default-directory (locate-dominating-file (expand-file-name ,dirname) ".git"))) ,@code)) (defun git-tools-grep (expression dirname) "Search a branch for `expression'. If there's a C-u prefix, prompt for `dirname'." (interactive (let* ((string (read-string "Search for: ")) (dir (if (null current-prefix-arg) default-directory (read-directory-name (format "Search for %s in: " string))))) (list string dir))) (git-tools-at-branch-root dirname (grep-find (format git-tools-grep-command (shell-quote-argument expression))))) On Sat, Dec 8, 2012 at 4:51 PM, Barry Warsaw <barry@python.org> wrote:
Hark fellow Emacsers. All you unenlightened heathens can stop reading now.
A few years ago, my colleague Jono Lange wrote probably the best little chunk of Emacs lisp ever. `M-x bzr-tools-grep` lets you easily search a Bazaar repository for a case-sensitive string, providing you with a nice *grep* buffer which you can scroll through. When you find a code sample you want to look at, C-c C-c visits the file and plops you right at the matching line. You *only* grep through files under version control, so you get to ignore generated files, and compilation artifacts, etc.
Of course, this doesn't help you for working on the Python code base, because Mercurial. I finally whipped up this straight up rip of Jono's code to work with hg. I'm actually embarrassed to put a copyright on this thing, and would happily just donate it to Jono, drop it in Python's Misc directory, or slip it like a lump of coal into the xmas stocking of whoever wants to "maintain" it for the next 20 years.
But anyway, it's already proven enormously helpful to me, so here it is.
Cheers, -Barry
P.S. Who wants to abuse Jono and Matthew's copyright again and provide a <shudder> git version?
;; Copyright (c) 2012 Barry A. Warsaw ;; ;; Permission is hereby granted, free of charge, to any person obtaining ;; a copy of this software and associated documentation files (the ;; "Software"), to deal in the Software without restriction, including ;; without limitation the rights to use, copy, modify, merge, publish, ;; distribute, sublicense, and/or sell copies of the Software, and to ;; permit persons to whom the Software is furnished to do so, subject to ;; the following conditions: ;; ;; The above copyright notice and this permission notice shall be ;; included in all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;; This code is based on bzr-tools.el ;; Copyright (c) 2008-2009 Jonathan Lange, Matthew Lefkowitz
(provide 'hg-tools)
(defconst hg-tools-grep-command "hg locate --print0 | xargs -0 grep -In %s" "The command used for grepping files using hg. See `hg-tools-grep'.")
;; Run 'code' at the root of the branch which dirname is in. (defmacro hg-tools-at-branch-root (dirname &rest code) `(let ((default-directory (locate-dominating-file (expand-file-name ,dirname) ".hg"))) ,@code))
(defun hg-tools-grep (expression dirname) "Search a branch for `expression'. If there's a C-u prefix, prompt for `dirname'." (interactive (let* ((string (read-string "Search for: ")) (dir (if (null current-prefix-arg) default-directory (read-directory-name (format "Search for %s in: " string))))) (list string dir))) (hg-tools-at-branch-root dirname (grep-find (format hg-tools-grep-command (shell-quote-argument expression)))))
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/quodlibetor%40gmail.com
On Dec 10, 2012, at 03:02 PM, Brandon W Maister wrote:
I also feel weird about adding a copyright to this, but how will other people feel comfortable using it if I don't?
Nice! I've been told that Emacs 23 is probably a minimum requirement because locate-dominating-file is missing in <= Emacs 22. I'm using Emacs 24.2 almost everywhere these days. -Barry
On Wed, Dec 12, 2012 at 01:27:21PM +0200, Petri Lehtinen wrote:
Brandon W Maister wrote:
(defconst git-tools-grep-command "git ls-files -z | xargs -0 grep -In %s" "The command used for grepping files using git. See `git-tools-grep'.")
What's wrong with git grep?
Or "hg grep", for that matter? -- Ross Lagerwall
On 2012-12-12, at 15:12 , Ross Lagerwall wrote:
On Wed, Dec 12, 2012 at 01:27:21PM +0200, Petri Lehtinen wrote:
Brandon W Maister wrote:
(defconst git-tools-grep-command "git ls-files -z | xargs -0 grep -In %s" "The command used for grepping files using git. See `git-tools-grep'.")
What's wrong with git grep?
Or "hg grep", for that matter?
hg grep searches the history, not the working copy. *-tools-grep only searches the working copy but automatically filters files to only search in files under version control. Which as far as I know is indeed what git-grep does already.
Yes indeed-- in my eagerness to make my first post to python-dev be well-received I completely forgot about git grep. brandon On Wed, Dec 12, 2012 at 9:20 AM, Xavier Morel <python-dev@masklinn.net>wrote:
On 2012-12-12, at 15:12 , Ross Lagerwall wrote:
On Wed, Dec 12, 2012 at 01:27:21PM +0200, Petri Lehtinen wrote:
Brandon W Maister wrote:
(defconst git-tools-grep-command "git ls-files -z | xargs -0 grep -In %s" "The command used for grepping files using git. See `git-tools-grep'.")
What's wrong with git grep?
Or "hg grep", for that matter?
hg grep searches the history, not the working copy. *-tools-grep only searches the working copy but automatically filters files to only search in files under version control.
Which as far as I know is indeed what git-grep does already. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/quodlibetor%40gmail.com
Ross Lagerwall wrote:
On Wed, Dec 12, 2012 at 01:27:21PM +0200, Petri Lehtinen wrote:
Brandon W Maister wrote:
(defconst git-tools-grep-command "git ls-files -z | xargs -0 grep -In %s" "The command used for grepping files using git. See `git-tools-grep'.")
What's wrong with git grep?
Or "hg grep", for that matter?
hg grep searches in the repository history, so it's not good for this.
participants (6)
-
Barry Warsaw
-
Brandon W Maister
-
Georg Brandl
-
Petri Lehtinen
-
Ross Lagerwall
-
Xavier Morel