Deprecated: Return type of Pimple\Container::offsetExists($id) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php on line 133

Deprecated: Return type of Pimple\Container::offsetGet($id) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php on line 98

Deprecated: Return type of Pimple\Container::offsetSet($id, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php on line 79

Deprecated: Return type of Pimple\Container::offsetUnset($id) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/vendor-prod/pimple/pimple/src/Pimple/Container.php on line 143

Deprecated: Return type of iThemesSecurity\Lib\Lockout\Execute_Lock\Context::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/lockout/execute-lock/abstract-context.php on line 60

Deprecated: Return type of iThemesSecurity\Lib\Lockout\Execute_Lock\Context::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/lockout/execute-lock/abstract-context.php on line 66

Deprecated: Return type of iThemesSecurity\Lib\Lockout\Execute_Lock\Context::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/lockout/execute-lock/abstract-context.php on line 72

Deprecated: Return type of iThemesSecurity\Lib\Lockout\Execute_Lock\Context::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/lockout/execute-lock/abstract-context.php on line 76

Deprecated: Return type of iThemesSecurity\Lib\Lockout\Execute_Lock\Context::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/lockout/execute-lock/abstract-context.php on line 56

Deprecated: Return type of ITSEC_Lib_Distributed_Storage_Cursor::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/class-itsec-lib-distributed-storage.php on line 578

Deprecated: Return type of ITSEC_Lib_Distributed_Storage_Cursor::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/class-itsec-lib-distributed-storage.php on line 585

Deprecated: Return type of ITSEC_Lib_Distributed_Storage_Cursor::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/class-itsec-lib-distributed-storage.php on line 606

Deprecated: Return type of ITSEC_Lib_Distributed_Storage_Cursor::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/class-itsec-lib-distributed-storage.php on line 613

Deprecated: Return type of ITSEC_Lib_Distributed_Storage_Cursor::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/class-itsec-lib-distributed-storage.php on line 620

Warning: Cannot modify header information - headers already sent by (output started at /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/lib/class-itsec-lib-distributed-storage.php:545) in /srv/sidawson.com/public/htdocs/wp-content/plugins/wp-super-cache/wp-cache-phase2.php on line 1544

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /srv/sidawson.com/public/htdocs/wp-content/plugins/better-wp-security/core/core.php on line 1092
Si Dawson . Com » 2012 » January
25.Jan.2012

Find non-commented Python lines in Komodo

I’ve been doing a lot of large scale refactoring recently.

This entails a lot of “find all instances of this and replace it with that” – in non-trivial ways (of course – any monkey can do a search & replace).

Obviously I also want to only bother with non-commented lines of code.

I use Komodo for my Python coding, and while it’s a great IDE in a lot of ways, it would appear I’m the first coder that’s ever wanted to search only active lines of code (/sarcasm). Komodo does have a great regex search feature though, so I put that to use.

After much head scratching (every regex engine has its own delightful little quirks) I found this incantation:

^\s*[^#\n]*find.*$

Which will find all single-line non-commented instances of ‘find’.

Now, bugger typing that mess in every time I want to find something, so here’s a better way.

Go View | Toolbox (so the toolbox appears on the right hand side). Then right-click & “Add New Macro”. Give it a sensible name and enter this into the main text area:

if (komodo.view) {komodo.view.setFocus();}
var search = ko.interpolate.interpolateStrings(‘%ask:SearchFor:’);
Find_FindAllInMacro(window, 0, ‘^\\s*[^#\\n]*’ + search + ‘.*$’, 2, 0, false, false);

It has to be Javascript – Komodo doesn’t offer the %ask functionality in Python macro scripting (nice one, guys).

Next give it a decent key-binding on the second tab. Click in the “New Key Sequence” box and hit a vulcan key combo that works for you – I’ve used Ctrl-Alt-F – followed by clicking Add.

Hit OK & you’re ready to roll. Anytime you want to find non-commented lines of code, hit your key combo, type your search string and voila!

related

  • No Related Posts

Mastodon