by crazygringo · 14y ago · 0 comments
I mean, I've never really felt the need to program an add-on to text editor. I download syntax highlighting packages, and there are common macros like "remove trailing whitespace" already installed. Keyboard shortcuts can be changed in lots of editors and OS's. In the past, I've definitely been upset that a particular editor didn't support a particular feature, but by now they've progressed enough that I don't really feel that anymore.
- A little hook to use an external Python program (cheating, I know) to look up the definition of the word under the cursor in the OS X dictionary.
- Several customizations for org-mode, which I use for anything where I want to make an outline, including and especially to-do lists.
- I actually still have some code to do "smart tabs" (http://www.emacswiki.org/SmartTabs) for some modes, though that's now probably obsolete if I would only configure up the code mentioned in that list for C modes. (I'm already using it for e.g. Python code.)
- Some configuration for LaTeX editing, like packages AUCTeX doesn't know about, converting words/phrases into \gls (glossary) references.
I actually have less custom stuff in .emacs than I thought. Having a programmable editor does mean that it's relatively easy for other people to write some really useful stuff which I then get to use. I have some local modifications to other people's packages which I don't have time to enumerate right now.
"Common" macros are the least interesting. The most interesting macros are the ones with no name, the one-time ones that you build on the fly. You have a file with ten thousand lines of:
foo.rb
bar.rb
baz.rb
…
… [9997 more lines like these]
and you need to turn the file into something like this: // Run the foo command
def foo()
end
// Run the bar command
def bar()
end
// Run the baz command
def baz()
end
… [9997 more blocks like these ]
That's 56 keystrokes in emacs: You record a macro that transforms one line appropriately, then execute it 9999 more times, all on the fly in about twenty seconds.1. `command + A` to select all
2. `command + shift + L` to split the multi-line selection into multiple single line selections (one curser at the end of each line)
3. `delete delete delete` to get rid of ".rb" on each line
4. `command + shift + ←` to select the identifier
5. `command + C` to copy each identifying word on each line (!!!!)
6. `←` to get to the beginning of the line
7. Type "// Run the "
8. `command + V` to paste each identifier on each line correctly (!!!!)
9. Type " command\ndef "
10. `command + →` to go past the identifier already there
11. Type "()\nend\n"
Also took about twenty seconds. This multi curser thing has been completely redefining how I mass edit code - it's quite fantastic, and as far as I know ST2 is the only editor that does it this wonderfully.
What's the "minimap", the scrollbar that is a shrunken version of the document? The "multiple carets" feature seems handy. Are there any other standout features, compared to vim or emacs (not, say, TextMate)?
qrIdef<space><esc>f.Di()<return>end<esc>jq
qr ' record a macro into register r
I ' insert mode at start of line
def<space><esc> ' type def then exit insert mode
f. ' find the dot
D 'delete the rest of the line
i()<return>end<esc> ' type () return end
j ' next line down
q ' exit macro recording
call it with 9999@r
This looks unwieldy but it's all done interactively. (also if you mess up and you want to rework the macro you can paste it out with "rp to paste the r register rework it and then put it back into another register. 0"ry$ (start at column 0 then into r register r yank to end of line)
cat file | perl -p -e 's-\s(.)\.rb-// Run the $1 command\ndef $1()\nend\n-'
start recording a macro:
qa
Then enter this sequence of keystrokes[1]: 0veyO// Run the ^R" command<esc>j0f.C()<cr>end<cr><esc>
Then exit macro recording with: q
Then enter the command: :g/.rb$/ norm @a
to run the macro on every line ending with .rb (allowing comments in the input, just because (of course it would be nice to make that regex in :g look for "lines that start with comments" and ignore them explicitly)).
If I counted right, thats 57 keystrokes, and I might have been slightly inefficient in my usage, of course, if that one keystroke is part of a command my fingers just do, there is no effective difference :)
[1] I know it was exactly that sequence because I just pasted the macro buffer, which of course can then be edited, saved back to the buffer and run in edited form.
Also, you don't have to actually program the editor yourself to reap the benefits of a programmable editor. Let's be honest, most modern editors have mostly overlapping functionality. However, one of the benefits of emacs being programmable is that it's self documenting. I can find out how to capitalize a word problematically without having to go to google by using `M-x apropos RET capitalize RET`.
It's not always about programming. It's about configuring and extending to suit it to your problem.
Pylinting and running python code. ,c(mapped to :make, not shown here) to pylint(not need as I run syntastic but still), ,x to run
augroup python
au!
autocmd FileType python nnoremap<buffer> ,x :w<CR>:!/usr/bin/env python % <CR>
autocmd FileType python setlocal nosmartindent
autocmd FileType python setlocal makeprg=pylint\ --reports=n\ --output-format=parseable\ %:p
autocmd FileType python setlocal errorformat=%f:%l:\ %m
autocmd BufRead python setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
autocmd FileType python setlocal path+=$PYTHONDIRS
augroup end
ERB and Jinja2 shortcuts. \1 for <% {cursor_here} %>, \2 for <%= {cursor_here} %> etc inoremap \1 <%<Space><Space>%><Esc>2hi
inoremap \2 <%=<Space><Space>%><Esc>2hi
inoremap \3 {%<Space><Space>%}<Esc>2hi
inoremap \4 {{<Space><Space>}}<Esc>2hi
A mini calculator function, lots of snippets, some saved macros etc.It's not about changing keyboard shortcuts. It implies you can only remap what already exists. It's about giving you infinite canvas to paint on. This isn't unique to Vim. I am just saying having the capability to do so is important.
I have a function for my work log which gets the date, figures out the previous Monday's date and dumps a formatted weekly log for me to fill out.
I wrote an entire budget tracking application which generates a forecast and dumps it to a csv file
Wrote a utility to mark and optionally delete duplicate files in a dired buffer
Convert a windows path name to a cygwin one
Functions to add local sales tax and remove local sales tax, same for tips.
Perforce source control, helpers to do blame functionality and other stuff that benefits from pulling Perforce output into a buffer
The most used feature would be keyboard macros which are endlessly useful for any repetitive editing task, which can show up unexpectedly at any point of the day
Occasionally have to write throw away custom code to create some boiler plate code, such as turn the API documentation for some errors into a C++ array of structures that can be manipulated in code
Full client for Redis
Yes, but you can't change the editing model as easily, e.g. converting a modeless editor in a modal one just by changing a few shortcuts.
My take is that there are two camps: people who adapt themselves to the tools they use and people who try to adapt their tools to their ways and their ever-changing view of the world. The former want the tool to help them to get things done, the latter want the tool to help them to get things done their own way. The former look at tools as tools, the latter look at tools as extensions of themselves.
Highlights: a Python IDE with refactoring, inference, search, etc.
Some hacks for TRAMP which lets me remotely edit content on arbitrary servers transparently.
A Python repl.
A generic compliance checker for Python code.
An undo module that presents undo/redo history as a visible tree that you can traverse arbitrarily.
A git client that has some EXCELLENT features.
A function to dynamically reload my environment.
A macro for my python debugger injector.
Code to unhtml HTML content and a whitespace cleaner-upper.
An interactive environment to experiment with and test regex.
A mode for CSS that highlights hex-values with the colors they represent, making their properties visual.
An interactive HTTP REST client interface for testing HTTP APIs.
A clone of hacker-typer in elisp.
Modes for clojure, erlang, haskell, rust, etc.
And a nyan-cat for my progress bar.