Emacs tips and tricks

Forum rules
Share your brain ;)
User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Fri Oct 31, 2014 3:26 pm

^ I love eshell, been using it a lot lately (it also works over TRAMP, which I find it very useful). I have to try this trick, thanks for sharing it.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Emacs tips and tricks

Unread post by rhowaldt » Sat Nov 01, 2014 1:17 pm

i just gotta say: there seem to be a lot more Emacs tips and tricks than Vim tips and tricks. even though i dont even use either of them, just from hearing you guys about it, in my mind Emacs still wins ;)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Sat Nov 01, 2014 3:21 pm

Well Rho, they're very different in what they actually are. Vi/Vim is a text editor that's extensible by scripts, while Emacs is a lisp-interpreter made to behave as a text editor. While that may not seem like a big deal at first glance...it means that you can change literally ANYTHING about emacs with some lisp.

Example: Bacon has mentioned before about how you don't need tmux if using emacs because it has active buffers and windows. On the other hand, if you are on the top window...but want to be on the bottom one with it on top, then the standard set of keybinds for making those moves are {C^x 0 C^x 4 b RET} or {C^x 0 C^x 2 C^x b RET} depending on which buffer/window your cursor is in. Well, fuck that...too many buttons. You'll end up with RSI.

Or, you can pull my window_swap.el script at github/lisp_scripts and put a line to load it in your init, and now {C^c s} 'swaps windows'. Problem solved. :)
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Emacs tips and tricks

Unread post by rhowaldt » Sat Nov 01, 2014 11:08 pm

so does that mean that, if you look at it honestly, there really is no reason whatsoever for the whole emacs/vim debate as they are essentially two different things and you end up basically comparing apples to pears?
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Sun Nov 02, 2014 4:43 am

Pretty much. Most us v them arguments are stupid, but in this case especially. It's like comparing a hammer and screwdriver and arguing about which is the best tool. It depends on what you need.

& @ GekkoP: eshell is something that I've always just sort of 'used' like ansi-term, but only recently got into REALLY playing with. It's addictive in that it's a shell, but you can use elisp commands directly or as scripts. At the point where I really began to grok that I can type (count-windows) or (window-list) or whatever directly into the shell and get stdout as emacs would see it...well, then the horizons got a lot more broad. For instance, typing in $echo "what buffer" (buffer-name) is acceptable and you end up with a lisp list as output! My command line jazz just got that much more avant garde.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Emacs tips and tricks

Unread post by rhowaldt » Sun Nov 02, 2014 8:42 pm

thanks for explaining joe :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Sun Nov 02, 2014 9:21 pm

Ok, so here's something that I'm working on that I think is possibly worth sharing.

Using a shell of any kind to produce a process that you plan to keep running seems a bit redundant, and one of the most common things I do is start mpg123 and pick out a radio stream with it to listen to. So if I'm in emacs, I launch eshell (or Ansi-term which starts zsh) to launch a script (normally bash) to start mpg123 pointed at the stream I want. Meh, that's cheesy. So:

I am working on making a new module.

Essentially, putting this one in your load path will allow you to M^x eplayer-[TAB] to get a list of stations in a new window that shows the different stations. Once you select the one you want, it will fork a process of mpg123 and place the metadata in a new buffer named after the station you're listening to and notifying you of what you chose in the mini-buffer. Killing the meta-data buffer will kill the process, so it's easy to stop the stream.

I plan to add every station available from them over the next couple of days, and actually maintain this to keep it synced with somafm's direct servers. It currently works, it just doesn't have all the stations yet.

edit: pretty much caught up with the stations I want to track now. Let me know if you use this and run into any issues.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Mon Nov 03, 2014 12:46 pm

^ beautiful idea, I'll play with it later.
And about eshell: I'm with you, as I've been more into eshell than zsh lately.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Mon Nov 03, 2014 5:45 pm

In case you are using MELPA and didn't notice, it is about to change URL. Just change it like this in your init and you will be happy:

Code: Select all

(add-to-list 'package-archives
	     '("melpa" . "http://melpa.org/packages/") t)

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Emacs tips and tricks

Unread post by machinebacon » Tue Nov 04, 2014 1:31 am

DebianJoe wrote:Ok, so here's something that I'm working on that I think is possibly worth sharing.

Using a shell of any kind to produce a process that you plan to keep running seems a bit redundant, and one of the most common things I do is start mpg123 and pick out a radio stream with it to listen to. So if I'm in emacs, I launch eshell (or Ansi-term which starts zsh) to launch a script (normally bash) to start mpg123 pointed at the stream I want. Meh, that's cheesy. So:

I am working on making a new module.

Essentially, putting this one in your load path will allow you to M^x eplayer-[TAB] to get a list of stations in a new window that shows the different stations. Once you select the one you want, it will fork a process of mpg123 and place the metadata in a new buffer named after the station you're listening to and notifying you of what you chose in the mini-buffer. Killing the meta-data buffer will kill the process, so it's easy to stop the stream.

I plan to add every station available from them over the next couple of days, and actually maintain this to keep it synced with somafm's direct servers. It currently works, it just doesn't have all the stations yet.

edit: pretty much caught up with the stations I want to track now. Let me know if you use this and run into any issues.
That's superb, since M^x mpg123-open does not really open URLs. I think people can easily add their desired stream, maybe I'll fork this one later and add the shit from our radiolists.
Love you (in a homo way)!
..gnutella..

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Tue Nov 04, 2014 7:27 am

Note: I'm currently working on pointing the player at the .pls rather than the port number, since the ports at soma change, while the pls should be consistent from day to day. If you go to add streams, note that string substitution ("%s" variable) works well for a single argument, while using (concat "-@" variable) allows us to gang-load multiple argvs mixing variables and strings.

So, if your stream is something like "http://shitmusic.com:8000" then use the first format. If it's not a port number, such as a .pls, use the concat form.

Code: Select all

;; Type 1, string matching for a port number stream ;;
(setq bebl '"http://xstream1.somafm.com:8388") 
(start-process "Beat Blender" "Beat Blender" "mpg123" "%s" bebl)

;;Type 2, concat argvs for a .pls type stream ;;
(setq covr '"http://somafm.com/covers.pls")
(start-process "Covers" "Covers" "mpg123" (concat "-@" covr))
While this is baby's first elisp-to-*nix stuff, it can be frustrating to figure out on your own. It's good to be loved...however I get it. :D
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Wed Nov 05, 2014 8:45 am

Ok, I may totally overkill this over the next few days/weeks as I'm still digging into eshell, but I'm still working on some tweakage to get eshell to behave more like I want. One of the things I noticed was that 'clear' doesn't do anything:

Code: Select all

(defun eshell/clear ()
  "clears the eshell buffer"
  (interactive)
  (let ((inhibit-read-only t))
    (erase-buffer)))
...and now it does. :)
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Wed Nov 05, 2014 4:12 pm

Since we are loving eshell, I'll add this useful snippet.

Code: Select all

(add-hook 'eshell-mode-hook
	  (lambda ()
	    (local-set-key (kbd "C-c h")
			   (lambda ()
			     (interactive)
			     (insert
			      (ido-completing-read "Eshell history: "
						   (delete-dups
						    (ring-elements eshell-history-ring))))))
	    (local-set-key (kbd "C-c C-h") 'eshell-list-history)))
Ido-powered-up Eshell history.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Emacs tips and tricks

Unread post by machinebacon » Fri Nov 07, 2014 2:21 am

http://blog.gnumonk.com/2012/07/effecti ... part1.html

Maybe interesting things in there. :)
..gnutella..

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Fri Nov 07, 2014 6:41 am

^^ some very cool stuff in there! Some of the prompt options do not agree with my prompt setup, but they have the clear and a bunch of other neat snippets. I also like having '(emacs (file))' lead to (find-file file). I had 'ff' aliased to find-file, but this will probably prevent some typos. If you guys run across more of these, I'd like to see them. I am still just getting into what all can be done here.

I was pleased to find out that eshell gets along well with the kxt script I did for killx, and that by setting an alias {alias kxt /path/to/killxdots/kxt $1} the behavior is almost identical to any other shell. While it does spawn a subshell, it does cut out a lot of rewriting scripts.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: Emacs tips and tricks

Unread post by Dr_Chroot » Fri Nov 07, 2014 5:49 pm

^^ Fantastic! Thanks, MB. This was exactly the sort of thing I was looking for.
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Wed Nov 12, 2014 5:07 pm

If you don't know what to eat, just ask Emacs: https://github.com/balle/fooddice

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: Emacs tips and tricks

Unread post by Dr_Chroot » Wed Nov 12, 2014 5:11 pm

^ That is actually fairly humorous! I love it B)
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Emacs tips and tricks

Unread post by GekkoP » Fri Nov 14, 2014 7:22 pm

Up until today I have never heard of auto-insert. Turns out it is a pretty cool way to simplify your life in Emacs.

For instance, every time I create a new .org file, first thing I do is put this string at the very top of it:

Code: Select all

#+STARTUP: showall
Now, let Emacs take care of this, shall we?

Code: Select all

;; Auto insert custom text upon opening an org file
(auto-insert-mode)
(setq auto-insert-query nil)
(eval-after-load 'autoinsert
  '(define-auto-insert '("\\.org\\'" . "Org skeleton")
     '(
       "Short description: "
       "#+STARTUP: showall\n"
       > _ \n \n)))
This works only when I open the file for the first time, so exactly what I need. Check the links I provided above for other examples.

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: Emacs tips and tricks

Unread post by DebianJoe » Mon Dec 01, 2014 7:51 am

This one is super-easy to figure out, but assuming that you want to associate something other than the default Scheme (I think it's EdWin on some editions, Guile on others) with M^x run-scheme:

Code: Select all

(setq scheme-program-name "/full/path/to/interpreter")
In the case of Chicken, 'csi' is your REPL, so you want it instead of 'csc' (displayed example in scrot).
Attachments
2014-12-01-005436_1024x768_scrot.png
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

Post Reply