Live data from Hacker News

My Emacs Productivity Tricks/Hacks

mycpu.org

171–180 of 210 posts

Re: My Emacs Productivity Tricks/Hacks

#171

The one thing I consistently do in emacs that shocks my coworkers -- is running this (custom) function, that I call "arrayify": (defun arrayify (start end quote) "Turn strings on newlines into a QUOTEd, comma-separated one-liner." (interactive "r\nMQuote: ") (let ((insertion (mapconcat (lambda (x) (format "%s%s%s" quote x quote)) (split-string (buffer-substring start end)) ", "))) (delete-region start end) (insert in…

That's fantastic! I'm definitely adding that to my spacemacs setup.

I usually end up doing that in two steps, with the first being a recursive macro to quote each line:

    q y s $ " A ,  0 j @ q
Then visually selecting and replacing new lines with spaces:

    V G :s/CTRL+Q CTRL+J/ /g

Re: My Emacs Productivity Tricks/Hacks

#172
post #4

also tramp, for editing files on any machine you can ssh into ... https://www.emacswiki.org/emacs/TrampMode

I used TRAMP a lot in the past, for some reason I have mostly forgotten about it. Maybe my projects just changed in nature?

Thinking of it, what I do rather frequently is ssh into a server and sudo -e there (root account is locked). I'm somewhat confident that TRAMP can be configured to do that. Need to investigate when I have time.

Re: My Emacs Productivity Tricks/Hacks

#173

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.

That's the whole point of a system like emacs: it enables the users to easily write solutions to their specific problems. It doesn't have to be general, it has to be easy to solve the problem at hand. It's the same with bash and unix tools. Writing general bash scripts is a nightmare, but datamunging particular problems works really well.

Re: My Emacs Productivity Tricks/Hacks

#174

The one thing I consistently do in emacs that shocks my coworkers -- is running this (custom) function, that I call "arrayify": (defun arrayify (start end quote) "Turn strings on newlines into a QUOTEd, comma-separated one-liner." (interactive "r\nMQuote: ") (let ((insertion (mapconcat (lambda (x) (format "%s%s%s" quote x quote)) (split-string (buffer-substring start end)) ", "))) (delete-region start end) (insert in…

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…

arrayify will also work on co-workers machines. You can open files on remote machines with tramp mode, and screenshare via zoom or something

Re: My Emacs Productivity Tricks/Hacks

#175
post #17

I've used Emacs for decades and still feel like I'm barely scratching the surface. What would really help me with articles like this one is more narrative on _why_ these particular modes are so useful. For example, it took me a long time to learn org-mode because I just didn't know what to do with it! I feel like Helm is similar, I've tried it briefly, but I'm not sure if or how it would fit into my workflow.

There are these series of "absolute minimums" (https://www.youtube.com/playlist?list=PLd_Oyt6lAQ8RgaMN3JnmZ...) centered on Spacemacs (a modified version of Emacs) but they go over helm and a bunch of different things. Should be generic enough to be useful.

Re: My Emacs Productivity Tricks/Hacks

#176

the others I cannot live without: neo tree winner mode god mode (I use instead of evil mode) avy (visually jump to any char on the screen) undo-tree (really neat, though I don't use it as much any more)

An alternative to winner-mode is eyebrowse, for anyone interested.

Re: My Emacs Productivity Tricks/Hacks

#177

The one thing I consistently do in emacs that shocks my coworkers -- is running this (custom) function, that I call "arrayify": (defun arrayify (start end quote) "Turn strings on newlines into a QUOTEd, comma-separated one-liner." (interactive "r\nMQuote: ") (let ((insertion (mapconcat (lambda (x) (format "%s%s%s" quote x quote)) (split-string (buffer-substring start end)) ", "))) (delete-region start end) (insert in…

I use a VIM macro for this.

Re: My Emacs Productivity Tricks/Hacks

#178

The one thing I consistently do in emacs that shocks my coworkers -- is running this (custom) function, that I call "arrayify": (defun arrayify (start end quote) "Turn strings on newlines into a QUOTEd, comma-separated one-liner." (interactive "r\nMQuote: ") (let ((insertion (mapconcat (lambda (x) (format "%s%s%s" quote x quote)) (split-string (buffer-substring start end)) ", "))) (delete-region start end) (insert in…

In vim: :' !awk '{printf("\"\%s\", ",$0)}' or to do the whole file: :%!awk '{printf("\"\%s\", ",$0)}' What I find nice about this approach is that I can use my knowledge of awk in other non-vim contexts. Similarly I can use my knowledge of other text processing commands to do things in vim, like reformat text into columns (:%!column -t) for example. Of course you could use vim commands to do the same thing: 0 GI" $ G…

You can use your knowledge of emacs in other non-emacs contexts as well! Elisp is a reasonably capable, if sprawling, programming language and comes with a lot of useful text and code munging stuff, as well as with cross-platform networking and filesystem support, and more esoteric stuff like calendar and symbolic/aribtrary precision math. And that's before installing any extra packages. I've written shebang scripts with Emacs (rather than say python or bash) on multiple occasions. Prior to windows growing linux support it probably also used to be one of the easier ways to write some unixy-feeling but cross-platform scripts; you can even craft a "shebang line" that works for both windows and unix. Having said that, due to general eco-systems advances, writing scripts in emacs has probably become less attractive than it used to be.

Re: My Emacs Productivity Tricks/Hacks

#179
post #34

Another beautifully designed piece of Emacs software is magit, where the defaults are extremely sane. The package is self-documented and you can learn it all by typing ? anytime. Being able to git log the file you are in is also a huge plus.

Funny, Magit never clicked for me. Maybe because I'm used to the quirks of the Git CLI and have aliases setup that speed up my workflow considerably, I never could reach the same productivity levels with Magit, and I've tried several times over the years.

Magit forces certain workflows because the author and community feel those work best, and stepping outside of that is often an exercise in frustration because you're not doing things "the Magit way". After going through a few issues on their tracker it was clear that there's no place for improvement suggestions unless it aligns perfectly with the maintainers' vision.

It feels very "holier than thou" and the constant hype around it everywhere is a bit off putting. Maybe it's just me, but I prefer using plain Git in a regular shell (Emacs shells are also unusable for me), with shell and Git aliases, and helper tools like scmpuff[1].

[1]: https://mroth.github.io/scmpuff/

Re: My Emacs Productivity Tricks/Hacks

#180
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.

I use emacs, but I don't think lsp-mode can do all the refactorings which intellij provides:

  Safe Delete
  Extract Method
  Extract Constant
  Extract Field
  Extract Parameter
  Introduce Variable
  Rename
  Inline
  Change signature
Refactorings are great, because you can do safe code transformations very quickly. If you get to know these features, it's hard to do without them.
Post reply on HN