Live data from Hacker News

My Emacs Productivity Tricks/Hacks

mycpu.org

141–150 of 210 posts

Re: My Emacs Productivity Tricks/Hacks

#142
a few I use:

  (defun shift-left  (beg end) (interactive "r") (shift-region beg end -1))
  (defun shift-right (beg end) (interactive "r") (shift-region beg end 1))

  (global-set-key [A-M-right] 'shift-right) ;; >> shift every line of region
  (global-set-key [A-M-left]  'shift-left)  ;; 

Re: My Emacs Productivity Tricks/Hacks

#143

I used to think that Emacs is some weird editor with absurd keybindings, until I learned lisp and understood what makes it so special. Now Emacs (Spacemacs[0]) is my main driver. [0] https://www.spacemacs.org

How did learning lisp help you understand the power of Emacs? Just starting down the Spacemacs road myself (from Sublime Text), and curious to hear more about your experience!

Emacs is basically a virtual machine for elisp with a couple of bindings to libraries for drawing things on a screen. Everything else, every bit of functionality, is written in elisp on top of that. For that to be possible elisp has to be a "real" programming language, with all the features you'd expect from a general-purpose language - and it is. It's also a lisp, however, so it has many features not found in most other languages.

Emacs is also an interactive IDE for elisp development. It provides all of the features you'd ever want from an IDE and then some. You get a linter, a debugger, semantic completion, ability to execute whole files or parts of them, data inspector/visualizer, finding definitions and references to symbols, a list of functions in a given file and across many files, shortcuts for common editing tasks, refactoring support, and so on. It's a very featureful, modern IDE with special emphasis on interactivity.

The effect of these two characteristics is that in Emacs you can easily find an implementation of any feature (no matter if it comes from Emacs core or some plugin), then edit it and see the results instantly (without the need for as much as saving the file), all the while having access to all of the IDE-like tools. You can customize every part of Emacs to exactly fit your needs - if there's something you'd like to change, but the feature's author didn't create a setting option for it, you can go locate and change the implementation in a few minutes.

When a computer game comes out, sometimes the authors also release a development kit with things like a map editor, theming support, tweaking AI and so on. Using (most) other editors is like simply playing the game: you can get better at it, but you can't change the rules. Using Emacs is like playing the game with the ability to instantly switch to the dev kit: you can simply play the game, but you also can bend, change, or rewrite the rules as you wish. With (most) other editors you're a consumer; with Emacs, you are the owner.

To really make use of all of that you have to know elisp, which is why knowing it is important. Of course, you can happily Emacs without dabbling in its configuration too much, but in that case, Emacs becomes just another editor with lots of awkward key bindings and a huge amount of cruft accreted during the last 40+ years.

Re: My Emacs Productivity Tricks/Hacks

#144

Earlier quoted context omitted.

I achieve the same by running two consecutive regex search and replace and a single backspace click s/^/"/ s/\n/“, / (Change all beginning of line to double pling. Change all new lines to double pling, comma, space) I don’t even store this as a procedure, I just ctr-f and do it from whatever text editor I’m in (I’m not an Emacs user) The nice thing about search and replacing your way out of problems is that it works…

I also prefer a more universal method. Arrayify is the equivalent of those useless specialized vegetable cutters and carvers in the kitchen that Alton Brown so hates. Search/Replace with Regex is universal . Arrayify breaks down with the slightest change in requirements.

And then you write some more elisp

Re: My Emacs Productivity Tricks/Hacks

#145
post #111

Earlier quoted context omitted.

Once you bind it to a key, though, it's a lot quicker. There is something to be said for emacs as a unified computing environment when compared to the UNIX way of doing things. Instead of wrangling different parts of the filesystem and tying them together with aliases and shell scripts, you can just version-control the productivity software (i.e. your emacs config) you write in the course of using emacs.

I'll be that guy ;) In vim/unix you can run this command (keybinding not included but simple enough): :' %!awk 'BEGIN {ORS=" "} {print "\" $1 "\"," } As for a unified computing environment, it is unified with the OS and not a world unto itself, there is no need to have one way of doing things within the editor and another if you want to script something. Both work just as well with version control, plus it gives you…

Yes, vim has a multiple cursor plugin that is useful for things like this: https://github.com/terryma/vim-multiple-cursors.

It's not as good as sublime in my experience, and I haven't used kakoune, but it's very serviceable.

Re: My Emacs Productivity Tricks/Hacks

#146
post #47

What is the emacs equivalent of package.json? (whenever I git clone my dotfiles on a new machine I usually have to comment out a bunch of stuff in my ~/.emacs because it's referencing packages which aren't installed, and I forgot where I installed them from, what version, etc...)

Most Emacs people use use-package for this.

Re: My Emacs Productivity Tricks/Hacks

#147
post #106
post #100

Earlier quoted context omitted.

And now since I'm sucked into the cult of the helm-o-verse I find I am binding many fewer keys. Just start typing 'M-x ar' and now it's the second item. Add another 'r' brings it to the fore. Less (for me) to remember. I note this mainly because it took me quite a long time to grok helm. Keep working with it!

You don't need Helm for that: smart M-x aka "smex" accomplished that for me and let me stay with ido, as I find Helm too intrusive.

Oh I really really loved smex. That's probably why it took me so long to get helm. helm doesn't improve on smex for this use case, I think. At least the stupid simple way I'm only going to use helm. But helm improves on other things spectacularly.

Re: My Emacs Productivity Tricks/Hacks

#148
post #121

Earlier quoted context omitted.

I mean, I play NetHack in it. I don’t think any IDE has that kind of flexibility.

http://eclipse-games.sourceforge.net/

That's nothing. You can do, in Emacs:

- Run Nethack

- Chat over IRC. Double combo with Bitlbee

- Chat over Slack/$whatever proto is designed in Elisp

- Write Interactive Fiction

- Emulate Interactive fiction with a Z machine in Elisp

- Write and read emails/news with GNUs

- Listen to music with EMMS

- M-x doctor because is too complex and you need to talk to someone

- Comment on HN with eww

- Do literate programming

- Do math, and with Maxima/R, algebra/statistics/whatever

- Use GIT with Magit

- org-mode. With this you could write three ebooks larger than the Java specs.

- org-babel. I forgot it. This is damn magic. Programming as if you were in a word processor, going back and forth, easily, showing up your results inline.

Re: My Emacs Productivity Tricks/Hacks

#149
post #119

Earlier quoted context omitted.

I like Emacs a lot, but it' definitely lacking most of the advanced IDE features, and the Emacs features that a decent IDE (read: Intellij) implement are usually "good enough" for me. People who've been using only Emacs for the last 20 years are in no position to comment on IDEs

With lsp-mode, there’s really nothing I can think of that emacs can’t do compared to IDEs. In fact, emacs blows them out of the water. Before LSP was invented, I would have agreed with you. But pretty much all IDE features have been commoditized by LSP now.

The man-or-boy test for IDEs was proposed long ago by Martin Fowler. If the editor can do the ‘extract method’ refactoring, then it's an IDE that properly understands the structure of the code.

More generally and forgivably, I'd say the IDE must know that two variables of the same name may be different variables, and to know which instances are which vars. Funny enough, this benefit of IDEs might rarely be felt with Javascript due to its uber-dynamic nature (at least without classes).

Re: My Emacs Productivity Tricks/Hacks

#150

Earlier quoted context omitted.

hm, I just select the text and do xclip -o | awk '{ print "\"" $0 "\"," }' find it simpler than 10 lines of lisp but what do I know :p

Once you bind it to a key, though, it's a lot quicker. There is something to be said for emacs as a unified computing environment when compared to the UNIX way of doing things. Instead of wrangling different parts of the filesystem and tying them together with aliases and shell scripts, you can just version-control the productivity software (i.e. your emacs config) you write in the course of using emacs.

A lot quicker to do something specific. What if your problem involves text, but is always changing? Then you need general tools and a way to compose them together. Just like general Unix command and Awk which automatically loop through files. I would go crazy if I had to write actual code to do that kind of work 50 times a week.
Post reply on HN