What are some useful TextMate features? [closed] - python

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I noticed that many people here use TextMate for coding on OS X. I've recently started using it, and although I like its minimalistic interface, it makes it harder to stumble upon cool features if you don't know what you're looking for.
So, what feature have you found most helpful for coding (mainly in Python)? Are there any third-party bundles I should know about, besides what's included?

Don't neglect the 'mate' command line tool. You can use it to pipe output into TextMate, so if you do the following...
diff file1.py file2.py | mate
...it will not only open in TextMate, but it is smart enough to know that you're looking at a diff and highlight lines on screen.
TextMate's SVN integration is great; it also seems to have bundles for some other version control systems as well.
Add GetBundle to browse the bundle repository. I found the jQuery bundle through it and it's very handy.
As others have mentioned, rolling your own bundle for frequently used snippets is very helpful. If you have some snippets that are specific to a project or framework, you might want to prefix all of them with a common letter to keep the namespace tidy.

Holding down option while dragging allows you to highlight a block of text. If you type while the highlight is active, your keystrokes appear on multiple lines.

Being able to write simple commands in any scripting language and bind them to a context-specific hotkey.

The Navigation menu commands Go to File (Command + T) and Go to Symbol (Command + Shift + T) are both extremely helpful.
Go to File, which works when you have a project open, lets you type any part of the file name to see only files that match what you've typed.
Go to Symbol has the same type-to-filter interface, but operates on what I'd call the basic block elements of your document. For example, if you're editing a class, Go to Symbol works on the method names, but in a CSS document, you'll be searching on your selectors. It's pretty awesome.

I mention some in a review on Boagworld, I find the snippets, project manager, columnar editing (hold down option while selecting stuff or push it after having selected stuff) and CSS scopes for syntax.

I like the integrated HTML/XML Tidy. Cmd-shift-H is your friend.
Also, nice integration with a variety of scp/sftp clients.

My favourite two features are auto-completion (bound to ⎋ [esc]), and column editing (bound to ⌥ [alt]) both of these things save me quite a lot of time, and are definitely 'robot ninjas'.
The book linked above is also a really useful into to the power of TextMate, although it doesn't specifically mention python.

Don't forget "Drag commands".
They give you the ability to drag, say, an image into a blog.html document and will then upload it to the proper folder and insert the markup for you.
Here is another example of how you can expand further on drag commands if you pair TM up with QuickSilver.
(Disclaimer: I wrote the blog post I linked to there. I still think it's cool though.)

It is worth noting here that there is a Windows alternative to TextMate called E Text Editor. It does pretty much everything TextMate does (apart from macros, but the author is working on this, I think), and even - shock, horror - does some things better, such as the superb bundles editor, the bundles manager, and the branching undo history. Update: and now there's Snippet Pipes.
So, not exactly a useful feature of TextMate as such, but very useful to know if you're a fan of TextMate and you have to use Windows for whatever reason.

The ease of snippet creation.
It's trivial to create new snippets that can accomplish a lot using replacements, tabbing order, and regex substitutions. Quickly assigning these to the tab key for specific languages makes me more productive. And makes me worry about code bloat. :-)

For me the best features are:
Projects - I know every IDE under
the sun has this but TextMate makes
this useful for all sorts of editing
and text processing tasks, and
moreover makes navigating around
these projects easy without ever
lifting your hands from the
keyboard. This is huge for Rails or
Grails projects or large programming
projects with many modules.
The excellent syntax highlighting
and 'snippets' for myriad languages
and tools
The excellent scripting language
support (Being able to evaluate
chunks of Ruby and the like with a
single key chord)
The built in Blogging bundle is
superb. I now use TextMate
exclusively for all my blog posts.
Columnar editing
The ability to use just about any
language or tool to extend TextMate,
Ruby, Perl, shell, name your poison.
An excellent mix of great Aqua GUI
support and excellent command line
support through the
mate and
commands, for
instance making it easy and pleasant
to use TextMate as your default
editor for your SCM.

Using snippets to expand into large, repetitive blocks of code and then using the tab key to move through and only edit the pieces I need to without having to use the mouse or arrow keys.

It's nice and lightweight and has all of the macros built-in for Ruby and let's you run Ruby code, or any other code for that matter just with a keystroke.

Check out ProjectPlus, it gives some useful options for the sidebar, it has SCM status badges for svn and git (though I find the git thing a bit buggy).
I like the fact that it can change the sidebar to an embedded panel on left or right (as opposed to the drawer that's default).

If, like me, you're borderline OCD when it comes to making code look neat, then Option+Cmd+] to line up all the assignments around the current line is awesome!

The mate command line tool is great, you can open an individual file or my favourite use of it is to open a directory of files as a project (e.g. mate .)

Checkout Zen Coding bundle . It gives you an awesome productivity boost to developing both HTML and CSS.

Related

Differences between several vim tags plugin

I have two questions actually.
First, as far as I know, there are two tags tools:
Ctags
GNU Global a.k.a. gtags
I'm wondering which one is more suitable if my daily works are concentrated on Ruby, Rails, JavaScript, and Python. Namely, dynamic languages.
I've googled a little bit, and it seems gtags is somehow equivalent to ctags + cscope?
Second, as for ctags, there are some vim plugins:
vim-tags: It can generate tags files in Vim through the command :TagsGenerate.
tagbar: A famous plugin. It seems it can generate tags on-the-fly.
vim-easytags: Seems like vim-tags, but with more features.
I'm wondering
Is there any overlap among these plugins?
If there are overlaps, how to integrate them or how to choose which one to use?
I know the it is not good to have two questions in one SO post, but I think these two questions are highly related as they are essential to the Vim+Tags combination.
Hope this question can serve as a foundation or tutorial for people who want to use tags but not familiar with it just like me. (I can't find a "modern" tutorial for vim+ctags, most post on the internet are out-dated IMO)
Thanks.
Update:
Basically, I want to be able to
Jump to the declaration of certain function
Jump to the usage of certain function
Make autocompletion more smarter. I mean, if I have
class Obj
def m1
puts "hello"
end
end
then I want autocompletion to show m1 when I type obj = Obj.new; obj..
As far as I know, YouCompleteMe can consume ctags' file, but I fail to set it up even I follow the instruction.
To be honestly, I don't really know what ctags can do or can offer. So please feel free to suggest more useful features. Thanks!
You can forget GNU GLOBAL right now because — last time I checked — it didn't support JavaScript at all. I don't know about Ruby and Python but it shouldn't be too hard for you to test it out.
Ctags works with JavaScript (and the others) but it doesn't like the "modern" way of writing JavaScript (inline callbacks, abused literal objects, self-invoking functions…). You can help it a little by adding the following lines to your ~/.ctags file:
--langmap=javascript:.js
--regex-javascript=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/F,function,functions/
--regex-javascript=/function[ \t]*([A-Za-z0-9._$()]+)[ \t]*\(/\1/F,function,functions/
--regex-javascript=/([A-Za-z0-9._$]+)[ \t]*=[ \t]*\{/\1/o,object,objects/
--regex-javascript=/^[ \t]*([A-Za-z0-9._$]+)[ \t]*[:][ \t]*[^\{]/\1/p,property,properties/
--regex-javascript=/^[ \t]+var[ \t]*([A-Za-z0-9._$]+)[ \t]*=[ \t]*[\d"'\[]/\1/v,variable,variables/
These work for me but my JavaScript is admittedly a bit "old school". Note that ctags is limited to "definitions/declarations".
There are also language-specific variants of ctags that usually give more sensible results like jsctags (JavaScript) or ripper-tags (Ruby)
Cscope, on the other hand, does "usage" and works for all your languages. Setting it up is a bit more involved than setting up ctags ad its usage is also a bit more complex but that's quite logical, given its features.
One "issue" you might have with cscope is that there are not many plugins written around it compared to ctags. That's a limitation worth considering.
As for the plugins you listed…
Yes, there's overlap between #1 and #3. #2 doesn't generate or use a tags file.
Try them, read their doc and decide for yourself.
You didn't even tell us how you wanted to use that feature? What are you after? tags generation? Jump to usage? Jump to declaration? An IDE-like "class explorer"? All of it?
edit
Let me address your comment and your edit:
Both ctags and cscope allow you to "jump to declaration" of an arbitrary symbol or (via custom mappings and settings for cscope) of the symbol under your cursor.
Only cscope allows you to "jump to usage".
Ctags being itself a little dumb and you using highly dynamic languages make ctags a bit useless for completion purpose. Some languages have better support than others, though, so you may find some helpful third party plugins like jedi-vim or Tern for Vim.
TagList and TagBar don't generate a tags file but they run do run ctags and consume its output. They just don't write it to disk. So yeah, you can use those plugins to "jump to delaration" but they are still isolated from Vim's built-in ctags support which can lead to issues.
See :help ctags and :help cscope to get a feeling of what they can do.

Sublime Text editor plug-in, scan div id's and classes

I'm aware I'm supposed to show some starting code to give you a clue as to what I'm trying to do, but I'm really at a basic level and I can't find any resources to show me what I'm after. Basically, I'm trying to write a plug-in for Sublime Text editor, which selects all div ID's then outputs them into a file. What's the best approach? It seems like it should be easy, but I'm not too sure.
Thanks in advance for your help,
Ewan
This looks like a good place to start: http://www.sublimetext.com/docs/plugin-basics
Look at http://www.sublimetext.com/docs/2/api_reference.html, though be advised that Sublime Text 3 is currently in beta. It introduces changes to the plugin api, and a requirement to support Python 3. See http://www.sublimetext.com/docs/3/porting_guide.html
Assuming you have some familiarity with python, I would start with this tutorial on for writing plugins (Link). The author of that tutorial wrote, among other things, package control. Granted, it is for ST2, but for what you are trying to do, I don't for see any major issues with writing a plugin that is compatible with both ST2 and ST3.
How you go about writing your particular plugin is up to you. One approach may be leveraging the view.find_all() method. This takes a regular expression and returns a set of regions. From these regions, you can grab the text, and subsequently the IDs for the divs. There may be a better way, but that might work as an initial attempt. Writing to a file can be done through the usual python means.

What are some good projects to make for a newbie Python (but not new to programming) developer? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm downloading Python 3.1.1 and that comes with the IDLE correct?
I'm also downloading QT for Windows which I'm told is a good GUI framework to work with Python.
What projects should I try to make in order to grasp some of the goodies Python brings to the table?
Thanks a bunch SO.
I highly recommend
http://www.diveintopython3.net
It assumes you already understand programming, and walks you through examples that demonstrate the unique abilities of Python.
Do the next project you intended to program with your prefered language with Python.
If you are new to python, why not start with some simpler command line projects? I know you said you are not new to development, but maybe you should spend some time with the core python stuff before tacking on a GUI framework. Just a suggestion.
Also, I would point out that Python 3+ code looks a bit different than a lot of the python 2.x code samples you will see around the internet. I have found Python 3 to be not the best in terms of backward compatibility. You might want to start out with a 2.x version of Python to get the most out of the plethora of Python tutorials on the internet, then move to Python 3 if you need it.
Write a simple Text Editor.
That was one of the projects i started when i first learned python. It gets you used to the GUI framework, file IO, many types, OOP, lots... It's something that you can grow over time as your confidence builds and it's cross platform so it's handy.
If python is your first dynamic lanugage you might want to play with some of it's dynamic aspects.
For example, using the getattr and setattr methods on objects, you could write a class that provides a fluent way of accessing elements from an XML document. Rather calling methods on an object with parameters like 'xml.getnode("a").getnode("b")' you could dynamically lookup the nodes as attributes and allow 'xml.a.b' instead. I thought this was very cool having come from static languages.
Note that this won't neccessarily give you a great feel for python in general (although you'll pick up the language as you go) but it will give you a taste of what is possible in dynamic languages.
PythonChallenge
Code Golf
Google Code Jam
These are good ways to practice learning Python.
Might I also suggest that you consider using a different IDE.
If you are interested in GUI programming, I would suggest looking into wxPython, PyWin32, easyGUI, TkInter (which is bundled with the Python distribution)
Python Challenge This is fun and interesting to learn Python programming.
While it is a matter of personal preference, I certainly wouldn't want to play around with a GUI framework when starting out -- I would want to get a feel for the language first by playing around with smaller snippets, such as those suggested on Code Golf. While getting your code to fit into the smallest number of bytes perhaps isn't the best way to learn good design, I think it's a good way to learn parts of the language. Certainly, just doing the tasks without necessarily trying to compact them down excessively could be helpful.
A project I wish someone would write: a friendly GUI that wraps around the scanner library and the PDF library, and lets the user easily scan and file documents.
It would have a toolbar with big buttons: "scan letter", "scan brochure", "scan photo". These would respectively choose high-resolution black-and-white, medium-resolution color, and high-resolution color.
The user would plop down the document and hit one of those buttons. Python would wake up the scanner and have it scan, and then would use Python Image Library or something to auto-detect the size of the actual scanned document and auto-crop down to minimal size.
For "scan photo" you would get a JPEG. For the others, you would get a PDF. And it would have an option where you could scan several pages and then select the scanned pages, and say "group" and it would make a single PDF out of them.
Other useful toolbar buttons would be: "Copy Letter", "Copy Brochure", "Copy Photo". These would scan and then immediately print on an appropriate output device (or just on the default output device for your first version).
If you want to go crazy, you could add an OCR function to try to recover searchable text from the scanned images, and put that in the PDF as tags or something.
Someday I will write this if nobody else does...

Python/Django plugin for Dreamweaver

Does a plugin exists for Python/Django into Dreamweaver? Just wondering since Dreamweaver is a great web dev tool.
I remember looking for a plugin too, but came across this stumbling block:
Designers are assumed to be comfortable with HTML code. The template system isn’t designed so that templates necessarily are displayed nicely in WYSIWYG editors such as Dreamweaver. That is too severe of a limitation and wouldn’t allow the syntax to be as nice as it is. Django expects template authors are comfortable editing HTML directly.
That being said, I found a Dreamweaver extension whilst having another quick look, so give it a try and let us know how it goes! From experience, the Eclipse solution offered by Paolo works very nicely, and the Komodo plugins look great, too. I know you are looking for a graphical editor, but emacs does a very nice job ;)
As far as I know there's no Django-specific IDE plugins out there.
However I use Eclipse with PyDev for my Django/Python needs and it is quite nice.
Found one from some guy named Beshr Kayali, but I can't try it myself, since I don't have Dreamweaver.
Beshir Kayali's plugin fails installation for DW CS5 and Extension Manager CS4.
Irony that it asks for DW CS4 or better, else "upgrade" Extension manager to CS3.
I could put some effort in to make this work, yet this is the sole review of the extension:
I allows you to insert 6 kinds of template tags; if, for, template variable, block, comment, and tags. You press a button and then get a dialog box asking you for some info with maybe a few options. It doesn't actually do too much from what I can tell, definitely skippable.

What refactoring tools do you use for Python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I have a bunch of classes I want to rename. Some of them have names that are small and that name is reused in other class names, where I don't want that name changed. Most of this lives in Python code, but we also have some XML code that references class names.
Simple search and replace only gets me so far. In my case, I want to rename AdminAction to AdminActionPlug and AdminActionLogger to AdminActionLoggerPlug, so the first one's search-and-replace would also hit the second, wrongly.
Does anyone have experience with Python refactoring tools ? Bonus points if they can fix class names in the XML documents too.
In the meantime, I've tried it two tools that have some sort of integration with vim.
The first is Rope, a python refactoring library that comes with a Vim (and emacs) plug-in. I tried it for a few renames, and that definitely worked as expected. It allowed me to preview the refactoring as a diff, which is nice. It is a bit text-driven, but that's alright for me, just takes longer to learn.
The second is Bicycle Repair Man which I guess wins points on name. Also plugs into vim and emacs. Haven't played much with it yet, but I remember trying it a long time ago.
Haven't played with both enough yet, or tried more types of refactoring, but I will do some more hacking with them.
I would strongly recommend PyCharm - not just for refactorings. Since the first PyCharm answer was posted here a few years ago the refactoring support in PyCharm has improved significantly.
Python Refactorings available in PyCharm (last checked 2016/07/27 in PyCharm 2016.2)
Change Signature
Convert to Python Package/Module
Copy
Extract Refactorings
Inline
Invert Boolean
Make Top-Level Function
Move Refactorings
Push Members down
Pull Members up
Rename Refactorings
Safe Delete
XML refactorings (I checked in context menu in an XML file):
Rename
Move
Copy
Extract Subquery as CTE
Inline
Javascript refactorings:
Extract Parameter in JavaScript
Change Signature in JavaScript
Extract Variable in JavaScript
WingIDE 4.0 (WingIDE is my python IDE of choice) will support a few refactorings, but I just tried out the latest beta, beta6, and... there's still work to be done. Retract Method works nicely, but Rename Symbol does not.
Update: The 4.0 release has fixed all of the refactoring tools. They work great now.
I would take a look at Bowler (https://pybowler.io).
It's better suited for use directly from the command-line than rope and encourages scripting (one-off scripts).
Your IDE can support refactorings !!
Check it Eric, Eclipse, WingIDE have build in tools for refactorings (Rename including). And that are very safe refactorings - if something can go wrong IDE wont do ref.
Also consider adding few unit test to ensure your code did not suffer during refactorings.
PyCharm have some refactoring features.
PYTHON REFACTORING
Rename refactoring allows to perform global code changes safely and instantly. Local changes within a file are performed in-place. Refactorings work in plain Python and Django projects.
Use Introduce Variable/Field/Constant and Inline Local for improving the code structure within a method, Extract Method to break up longer methods, Extract Superclass, Push Up, Pull Down and Move to move the methods and classes.
You can use sed to perform this. The trick is to recall that regular expressions can recognize word boundaries. This works on all platforms provided you get the tools, which on Windows is Cygwin, Mac OS may require installing the dev tools, I'm not sure, and Linux has this out of the box. So grep, xargs, and sed should do the trick, after 12 hours of reading man pages and trial and error ;)

Categories