Gedit File Search Plugin 0.2 is out

After long hiatus, there’s a new version of the File Search plugin for Gedit. However, the only visible change is that results are now sorted. Most changes have happened under the hood meanwhile, by reorganizing the search implementation. Hopefully this will allow for some more goodies in the future (Progress bar? Integration with some Project Manager plugin?); but for now I’m glad that this change is done.

So please give it a try, and if you notice anything weird about it, please leave a comment! I’m especially interested to hear if there’s any visible slowdown due to sorting… Theoretically it should be slower, but in practice it shouldn’t be noticeable.

Btw. many thanks for your feedback so far! It’s really good to see how the plugin is used “in the wild”, and I’m planning to get lots of the ideas and comments into the next version – hopefully without such a long delay this time :-)

Advertisements

46 Responses to “Gedit File Search Plugin 0.2 is out”

  1. triathlon Says:

    Any chance we get it to work on os x now that gedit has been ported? It starts up fine but never returns from a search.

    Thanks for an awesome plugin by the way, it was the last missing piece to making gedit the ultimate editor for me.

  2. olivergerlich Says:

    Didn’t know there’s a Mac port of Gedit! Getting the search plugin working there would be cool!

    Technically, there might be some difference in the OS X versions of grep or find commands, or in the shell. I don’t have access to such a system; maybe we get the plugin working if you or someone else is willing to put some debugging into it.

    To start, here are two commands that the plugin uses; if you execute these in the Terminal, what is the output?

    find $HOME -xtype f -print

    grep -H -I -n -s -Z -F -e ‘abc’ ~/somefile

    (replace “somefile” with the name of a text file in your home directory).

    Sorry for the vague description; I’m not familiar with OS X :-( .

  3. triathlon Says:

    find $HOME -xtype f -print doesn’t recognize xtype

    find $HOME -type f -print lists all the files in $HOME with full path

    grep -H -I -n -s -Z -F -e ‘abc’ ~/somefile returns nothing, the quotes confused grep

    grep -H -I -n -s -Z -F -e abc ~/somefile returns

    /Users/triathlon/somefile10: abcdefg

    I can help with debugging.

  4. triathlon Says:

    thought it might be the xtype thing so I changed it in the code, then I got the following message when running via command line

    find: !: nothing between ! and -o

    I uncommented a print line in RunCommand and got the following:

    executing command: [‘find’, ‘/Users/triathlon/work/www3/’, ‘(‘, ‘!’, ‘-path’, ‘/Users/triathlon/work/www3/*/.*’, ‘)’, ‘(‘, ‘!’, ‘-path’, ‘/Users/triathlon/work/www3/.*’, ‘)’, ‘(‘, ‘!’, ‘-name’, ‘*~’, ‘!’, ‘-name’, ‘.#*.*’, ‘)’, ‘(‘, ‘!’, ‘-path’, ‘*/CVS/*’, ‘!’, ‘-path’, ‘*/.svn/*’, ‘!’, ‘-path’, ‘*/.git/*’, ‘!’, ‘-path’, ‘*/RCS/*’, ‘)’, ‘(‘, ‘-false’, ‘-o’, ‘-name’, ‘*.js’, ‘-o’, ‘-name’, ‘*.py’, ‘-o’, ‘-name’, ‘*.html’, ‘)’, ‘-type’, ‘f’, ‘-print’]

  5. triathlon Says:

    thought it might be the -name parameters so I removed all file types from the dialog and got this:

    executing command: [‘find’, ‘/Users/triathlon/work/www3/’, ‘-type’, ‘f’, ‘-print’]

    No error this time, it just hangs. Tried cancelling via the stop button and then I get:

    OSError: [Errno 2] No such file or directory: ‘/proc’

    Out of my depth now, let me know if you want me to try something else.

  6. olivergerlich Says:

    Wow, thanks for the info! I’ll try to put together a version that has some of these problems fixed and that gives better debug output; should be ready in a few minutes.

    For now, http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/find.1.html confirms that -xtype is not supported – not sure if there’s a good replacement, or maybe -type is fine in this case.
    The “/proc” directory is indeed missing on Mac OS X, but maybe this functionality isn’t even necessary any more (it was used for killing the Find and Grep processes, but I think that can be done differently now).

    Note sure about the “find: !: nothing between ! and -o” problem or the hanging Find command; better debug output should help.

  7. olivergerlich Says:

    Here’s a file-search.py file with some more debug output and hopefully fixed Cancel button (actually I think the Cancel thing was broken on Linux as well after the latest changes):
    http://github.com/oliver/gedit-file-search/raw/macport/file-search.py

    There’s a new “macport” branch at http://github.com/oliver/gedit-file-search/tree/macport now where these changes will be collected.

    The problem with -name parameter is probably still in this version, but the simple Find command should give better debug output now.

  8. triathlon Says:

    Tried it out. The -o error has gone when I specify file types but find still does not return (with file types or not). “ps aux | grep find” returns

    triathlon 7616 0.0 0.0 0 0 s001 Z+ 9:12PM 0:00.00 (find)

    pushing “stop” prints out the following:

    (cancelling command)
    main pid: 7616; num procs: 1
    killing pid 7616

    but ps aux has the process still running forever, doesn’t disappear until I quit gedit.

  9. Mauricio de Amorim Says:

    Congratulations, I like this plugin, itś very useful and helped me in very many taks. I write a post about File Search in Portuguese and I left my recommendations. I hope the guys here in Brazil can use this tool in their projects.

    Thank very much!!

    Hug.

  10. Mauricio de Amorim » Gedit com busca de texto Says:

    […] gostou do plugin deixe um comentário para o autor, pois é legal copiar e mais legal ainda é reconhecer os […]

  11. Tecnologia de Internet (Locaweb) » Blog Archive » File Search no Gedit Says:

    […] gostou do plugin File Search deixe um comentário para o autor, pois é legal copiar e mais legal ainda é reconhecer os […]

  12. soiamso Says:

    get_uri() return a quoted uri.

    but need unquoted searchDir.

    file-search.py commit :59888c1
    721c721
    searchDir = urllib.unquote(os.path.dirname(currFileDir[7:]))

    Wish the info above could help. May be the test suit’ path should contain non-ascii character,

    Thanks for your great plugin!

  13. olivergerlich Says:

    soiamso: thanks for finding this bug and posting a solution! It’s already commited: http://github.com/oliver/gedit-file-search/commit/ab7f2b406e1e1e1152be01863b94dd6535880cf9

  14. redsox Says:

    Cool plugin. Simple and easy to use.
    thanks-

  15. russ Says:

    Pretty good, it is very fast and seems to find everything.

    Thanks for putting it up for us to download

    My only suggestion, in the search results – add “Contract All” and “Expand All” somewhere so when i get 60 files, i dont have to manually do it to each to look through file names only

  16. Leonardo Borges Says:

    Finally a Find in Files plugin that works! :)

    Thanks a lot for this.

  17. F. Says:

    Great plugin, it works and is fast. Just a suggestion: is it possibile to persist plugin in the bottom of the gui ? i like di hide and maybe review the last search easily.

  18. olivergerlich Says:

    F: currently all search results remain in the bottom panel until you click the Close button in a tab. If the bottom panel is hidden you can show it with Ctrl+F9. Could you clarify your suggestion?

    Thanks, Oliver

  19. mandrillo Says:

    thanks! plugin very useful!
    When out the “search and replace in directories” plugin?

  20. olivergerlich Says:

    mandrillo, nice to hear you like the plugin :-)

    Unfortunately I currently don’t have much time to work on it. So I don’t think I can add search-and-replace functionality soon; sorry.

  21. strandjata Says:

    Hi
    Thanks for the great plugin.
    I made a small change , added a whole word (on|off) functionality.
    If you think it is worth publishing I can send it to you.

    BR

  22. olivergerlich Says:

    strandjata, that functionality sounds very useful; and it would be nice if you could send it to me at olivergerlich at gmxde. However, I currently don’t have much time to work on the plugin, but maybe I can find some time to add your changes.

  23. strandjata Says:

    I sent it this morning at the mail from the git logs , it has dot between your first and surname right ?

  24. olivergerlich Says:

    Thanks for the mail; I’ve just noticed that WordPress has removed some parts of my address but you figured it out correctly :-) I don’t have full email access at the moment and couldn’t reply. Will have a look at your changes when I’m back.

  25. Denis Says:

    Thanks a lot.

    Exactly what I needed !!!!

    Would it be possible to put all this files in a a directory in order to keep a .gnome2/gedit/plugins well organized ?

  26. Jeremy Walker Says:

    Thank you so much for this!

    I had pretty much given up on finding it and was resigning myself to having to create a whole plugin for it. So thank you for saving me so much time!

  27. weaz Says:

    Really great plugin for programming, thank you very much.
    JUst have two suggestions for it, perhaps one is even easier to solve:
    – add this plugin under the CTRL+F key combination; perhaps it is possible already
    – add search in new tab; checkbox that a new tab should be oppened with the results of the new search and a small list to reuse the existing search tabs

  28. olivergerlich Says:

    Nice to hear you like the plugin :-)
    Regarding your suggestions:
    – currently the search dialog can be opened with Ctrl+Shift+F key combo; Ctrl+F is already used for normal Search
    – such a feature might be useful, but I don’t quite like the thought of adding even more options to the search dialog. I’ll have to think about this.

  29. luke Says:

    love the plugin!

  30. luke Says:

    love it

  31. Guillaume Says:

    Great ! I’ve been searching it for years, your plugin is the only one that REALLY works !

    Thanks a lot :-)

  32. Mico Says:

    Thanks a ton for your efforts on this. Has saved me lots of time. Great job!

  33. Rob Says:

    Hi Oliver,

    Here’s a patch that adds highlighting of what you’ve searched and whole word searching. If there is a better way of sending you patches, please let me know.

    ———————————–
    diff –git a/file-search.glade b/file-search.glade
    index d2b5ffa..5599020 100644
    — a/file-search.glade
    +++ b/file-search.glade
    @@ -75,6 +75,17 @@
    True
    True

    +
    +
    +
    + True
    + True
    + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
    + Whole word
    + 0
    + True
    + True
    +

    False

    diff –git a/file-search.py b/file-search.py
    index 0fa71e9..96982d9 100644
    — a/file-search.py
    +++ b/file-search.py
    @@ -178,6 +178,7 @@ class SearchQuery:
    self.text = ”
    self.directory = ”
    self.caseSensitive = True
    + self.wholeWord = True;
    self.isRegExp = False
    self.includeSubfolders = True
    self.excludeHidden = True
    @@ -197,6 +198,11 @@ class SearchQuery:
    self.caseSensitive = True

    try:
    + self.wholeWord = gclient.get_without_default(gconfBase+”/whole_word”).get_bool()
    + except:
    + self.wholeWord = True
    +
    + try:
    self.isRegExp = gclient.get_without_default(gconfBase+”/is_reg_exp”).get_bool()
    except:
    self.isRegExp = False
    @@ -228,6 +234,7 @@ class SearchQuery:

    def storeDefaults (self, gclient):
    gclient.set_bool(gconfBase+”/case_sensitive”, self.caseSensitive)
    + gclient.set_bool(gconfBase+”/whole_word”, self.wholeWord)
    gclient.set_bool(gconfBase+”/is_reg_exp”, self.isRegExp)
    gclient.set_bool(gconfBase+”/include_subfolders”, self.includeSubfolders)
    gclient.set_bool(gconfBase+”/exclude_hidden”, self.excludeHidden)
    @@ -388,6 +395,8 @@ class GrepProcess:
    grepCmd += [“-i”]
    if not(self.query.isRegExp):
    grepCmd += [“-F”]
    + if (self.query.wholeWord):
    + grepCmd += [“-w”]

    # Assume all file contents are in UTF-8 encoding (AFAIK grep will just search for byte sequences, it doesn’t care about encodings):
    self.queryText = self.queryText.encode(“utf-8”)
    @@ -773,6 +782,7 @@ class FileSearchWindowHelper:
    query = SearchQuery()
    query.loadDefaults(self.gclient)
    self.tree.get_widget(‘cbCaseSensitive’).set_active(query.caseSensitive)
    + self.tree.get_widget(‘cbWholeWord’).set_active(query.wholeWord)
    self.tree.get_widget(‘cbRegExp’).set_active(query.isRegExp)
    self.tree.get_widget(‘cbIncludeSubfolders’).set_active(query.includeSubfolders)
    self.tree.get_widget(‘cbExcludeHidden’).set_active(query.excludeHidden)
    @@ -810,6 +820,7 @@ class FileSearchWindowHelper:
    query.text = searchText
    query.directory = searchDir
    query.caseSensitive = self.tree.get_widget(‘cbCaseSensitive’).get_active()
    + query.wholeWord = self.tree.get_widget(‘cbWholeWord’).get_active();
    query.isRegExp = self.tree.get_widget(‘cbRegExp’).get_active()
    query.includeSubfolders = self.tree.get_widget(‘cbIncludeSubfolders’).get_active()
    query.excludeHidden = self.tree.get_widget(‘cbExcludeHidden’).get_active()
    @@ -996,11 +1007,9 @@ class FileSearcher:
    if lineno > 0: # this is necessary for Gedit 2.17.4 and older (see gbo #401219)
    currDoc = self._window.get_active_document()
    currDoc.goto_line(lineno – 1) # -1 required to work around gbo #503665
    – currView = gedit.tab_get_from_document(currDoc).get_view()
    – currView.scroll_to_cursor()

    # workaround to scroll to cursor position when opening file into window of “Unnamed Document”:
    – gobject.idle_add(scrollToCursorCb, currView)
    + gobject.idle_add(scrollToCursorCb, self)

    def on_btnClose_clicked (self, button):
    self.destroy()
    @@ -1058,8 +1067,19 @@ class FileSearcher:
    clipboard.store()

    -def scrollToCursorCb (view):
    – view.scroll_to_cursor()
    +def scrollToCursorCb (searcher):
    + currDoc = searcher._window.get_active_document()
    + currView = gedit.tab_get_from_document(currDoc).get_view()
    + currView.scroll_to_cursor()
    +
    + flags = 0
    +
    + if searcher.query.caseSensitive:
    + flags = 2
    + if searcher.query.wholeWord:
    + flags = flags + 1
    +
    + currDoc.set_search_text(searcher.query.text, flags)
    return False

    def resultSearchCb (model, column, key, it):

  34. Rob Says:

    Looks like it didn’t like the glade file. I’ll modify the xml tags here and try once more. You can replace ~ with > and ` with < to get back to the patch.
    ———————————————–
    diff –git a/file-search.glade b/file-search.glade
    index d2b5ffa..5599020 100644
    — a/file-search.glade
    +++ b/file-search.glade
    @@ -75,6 +75,17 @@
    `property name="active"~True`/property~
    `property name="draw_indicator"~True`/property~
    `/widget~
    + `/child~
    + `child~
    + `widget class="GtkCheckButton" id="cbWholeWord"~
    + `property name="visible"~True`/property~
    + `property name="can_focus"~True`/property~
    + `property name="events"~GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK`/property~
    + `property name="label" translatable="yes"~Whole word`/property~
    + `property name="response_id"~0`/property~
    + `property name="active"~True`/property~
    + `property name="draw_indicator"~True`/property~
    + `/widget~
    `packing~
    `property name="expand"~False`/property~
    `/packing~
    diff –git a/file-search.py b/file-search.py
    index 0fa71e9..96982d9 100644
    — a/file-search.py
    +++ b/file-search.py
    @@ -178,6 +178,7 @@ class SearchQuery:
    self.text = ''
    self.directory = ''
    self.caseSensitive = True
    + self.wholeWord = True;
    self.isRegExp = False
    self.includeSubfolders = True
    self.excludeHidden = True
    @@ -197,6 +198,11 @@ class SearchQuery:
    self.caseSensitive = True

    try:
    + self.wholeWord = gclient.get_without_default(gconfBase+"/whole_word").get_bool()
    + except:
    + self.wholeWord = True
    +
    + try:
    self.isRegExp = gclient.get_without_default(gconfBase+"/is_reg_exp").get_bool()
    except:
    self.isRegExp = False
    @@ -228,6 +234,7 @@ class SearchQuery:

    def storeDefaults (self, gclient):
    gclient.set_bool(gconfBase+"/case_sensitive", self.caseSensitive)
    + gclient.set_bool(gconfBase+"/whole_word", self.wholeWord)
    gclient.set_bool(gconfBase+"/is_reg_exp", self.isRegExp)
    gclient.set_bool(gconfBase+"/include_subfolders", self.includeSubfolders)
    gclient.set_bool(gconfBase+"/exclude_hidden", self.excludeHidden)
    @@ -388,6 +395,8 @@ class GrepProcess:
    grepCmd += ["-i"]
    if not(self.query.isRegExp):
    grepCmd += ["-F"]
    + if (self.query.wholeWord):
    + grepCmd += ["-w"]

    # Assume all file contents are in UTF-8 encoding (AFAIK grep will just search for byte sequences, it doesn't care about encodings):
    self.queryText = self.queryText.encode("utf-8")
    @@ -773,6 +782,7 @@ class FileSearchWindowHelper:
    query = SearchQuery()
    query.loadDefaults(self.gclient)
    self.tree.get_widget('cbCaseSensitive').set_active(query.caseSensitive)
    + self.tree.get_widget('cbWholeWord').set_active(query.wholeWord)
    self.tree.get_widget('cbRegExp').set_active(query.isRegExp)
    self.tree.get_widget('cbIncludeSubfolders').set_active(query.includeSubfolders)
    self.tree.get_widget('cbExcludeHidden').set_active(query.excludeHidden)
    @@ -810,6 +820,7 @@ class FileSearchWindowHelper:
    query.text = searchText
    query.directory = searchDir
    query.caseSensitive = self.tree.get_widget('cbCaseSensitive').get_active()
    + query.wholeWord = self.tree.get_widget('cbWholeWord').get_active();
    query.isRegExp = self.tree.get_widget('cbRegExp').get_active()
    query.includeSubfolders = self.tree.get_widget('cbIncludeSubfolders').get_active()
    query.excludeHidden = self.tree.get_widget('cbExcludeHidden').get_active()
    @@ -996,11 +1007,9 @@ class FileSearcher:
    if lineno ~ 0: # this is necessary for Gedit 2.17.4 and older (see gbo #401219)
    currDoc = self._window.get_active_document()
    currDoc.goto_line(lineno – 1) # -1 required to work around gbo #503665
    – currView = gedit.tab_get_from_document(currDoc).get_view()
    – currView.scroll_to_cursor()

    # workaround to scroll to cursor position when opening file into window of "Unnamed Document":
    – gobject.idle_add(scrollToCursorCb, currView)
    + gobject.idle_add(scrollToCursorCb, self)

    def on_btnClose_clicked (self, button):
    self.destroy()
    @@ -1058,8 +1067,19 @@ class FileSearcher:
    clipboard.store()

    -def scrollToCursorCb (view):
    – view.scroll_to_cursor()
    +def scrollToCursorCb (searcher):
    + currDoc = searcher._window.get_active_document()
    + currView = gedit.tab_get_from_document(currDoc).get_view()
    + currView.scroll_to_cursor()
    +
    + flags = 0
    +
    + if searcher.query.caseSensitive:
    + flags = 2
    + if searcher.query.wholeWord:
    + flags = flags + 1
    +
    + currDoc.set_search_text(searcher.query.text, flags)
    return False

    def resultSearchCb (model, column, key, it):

  35. Alan Says:

    Great plugin. Do you have a paypal donate link?

  36. Julio Says:

    Great plugin. simpel and functional

  37. Brando Bandit Says:

    hi! thanks for this plugin! will this work in Ubuntu 10.04? please i would like to know. need this one. thanks!

  38. olivergerlich Says:

    Rob, sorry for the long delay, and thanks for your patch! I have just published a change that offers the whole-word option which Strandjata and you have both proposed, though it is now implemented in a different way to avoid the peculiarities of grep. I’d be glad if you could give it a test!

  39. olivergerlich Says:

    Alan: nope, no paypal link available as this is a pure hobby project and I don’t want no pressure :-)

    Brando: the plugin works fine in Ubuntu 10.04 for me. If you encounter problems, please tell me!

  40. Andy Fitzsimon Says:

    hey Oliver,

    Much love mate, I’m using file search all the time and have made a couple of small formatting modifications at pastebin.com/LddZcB8R

    Would you consider a collapse all /expand all button?
    Sometimes I don’t care for the contents and only want to see in which files strings occur. if one file includes 100’s of instances it kind of blows out the results view size

  41. olivergerlich Says:

    Andy, the Expand All/Collapse All feature is now available in the development version (eg. at http://github.com/oliver/gedit-file-search/raw/master/file-search.py).

    The changed colors you proposed were difficult to use in my default bright Gnome/Gedit theme; but I suppose if you use a dark theme the current colors are not very useful either :-)
    I’m not sure yet how to handle this – ideally the plugin would use the system-wide color for the yellow markers and some other system-wide color instead of blue result lines. But apparently it’s not that easy to get the values of these system colors.

  42. Miguel Rosales Says:

    Excellent tool, very useful, simple and well done.

  43. Andrew Niemants Says:

    Is there a way that I can search files that have been mounted with SSH for instance. I am able to edit them within gedit but I want to search through them the bookmark does not show up.

  44. olivergerlich Says:

    Andrew: searching remote folders is currently not enabled as it would require to transfer the content of all searched files over SSH. In my tests, this was very slow.

    However, you can give it a try yourself:
    – click Ctrl-Shift-F to open the File Search dialog
    – click Browse
    – navigate to your home directory
    – right-click in the right-side pane and select Show Hidden Files
    – go into the .gvfs folder in your home directory
    – there you find all remote directories (SSH etc) and can browse them as usual, and select one for searching

    Besides the slow performance, I’m not sure whether this feature would actually work on all systems (the user would have to have the gvfs-fuse-daemon running, which is not guaranteed).

    Still, I’d be interested in feedback whether this is actually a useful feature despite the performance.

  45. Andrew Niemants Says:

    Oliver,
    After some testing this weekend the proposed solution works well. I tried on multiple connections. Searching for the same term on each connection to get an idea of the time it takes. The slowest connection I tried was a 1/meg download 256k/upload as expected it took the longest at 5min. The same search on the local box was nearly instantaneous. I tried on a 10meg link as well and the search took less than a minute. I also tried on a gigabit network and the search was very very quick. So it would be a neat option to be able to enable but the work around is fine for now.

  46. Home Refinance Calculator Says:

    Hey There. I found your blog using msn. This is an extremely well written article.
    I will be sure to bookmark it and come back to read more of
    your useful information. Thanks for the post.
    I’ll certainly comeback.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: