Emacs tips and tricks

Forum rules
Share your brain ;)
User avatar
kondor
runs Stable
Posts: 35
Joined: Thu Jan 29, 2015 6:11 am

Re: Emacs tips and tricks

Unread post by kondor » Thu Apr 07, 2016 10:31 pm

@DrChroot:

I'm really grooving to Spacemacs, too. :) Since I hafta use vi/vim a lot anyway, evilmode is kind of a no-brainer. But if you're coming from years of vanilla emacs bindings, the evil-centric philosophy is obvious heresy. Also, the layer based configuration is different enough that it's probly gonna rustle some jimmies.

After a couple of emacs bankruptcies, though, layered configurations are exactly what I wanted out of emacs. I think the whole architecture jibes quite well with what John Wiegley is doing with the future of emacs as a platform -- discussed here:

http://sachachua.com/blog/2015/12/2015- ... -can-help/

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Emacs tips and tricks

Unread post by franksinistra » Fri Apr 08, 2016 5:51 pm

Recently i switched from mingus (due to random glitches and bug) to simple-mpc https://github.com/jorenvo/simple-mpc

made it look cool too, a la dmenu slash mpc (using hydra), you know i'm a bit too obsessed about colors and uniformed-look

Code: Select all

(use-package simple-mpc
    :config
    (progn
      (defun my-simple-mpc/state ()
        (propertize "" 'face '(:foreground "#b262af")))

      (defun my-simple-mpc/title (offset)
        (let* ((idx (simple-mpc-get-current-playlist-position))
               (pos (+ idx offset))
               (songs (split-string (shell-command-to-string "mpc playlist") "\n"))
               (title (when (> pos 0) (nth-value (1- pos) songs))))
          (propertize (or title "") 'face (when (/= offset 0) '(:foreground "#868dd9")))))

      (defhydra hydra-simple-mpc
        (:body-pre (setq hydra-is-helpful t)
         :post (setq hydra-is-helpful nil)
         :hint nil
         :color amaranth)
        (concat "\n"
                "%s(my-simple-mpc/title -1)" "\n"
                "    %s(my-simple-mpc/state) %s(my-simple-mpc/title 0)" "\n"
                "%s(my-simple-mpc/title 1)" "\n")

        ("<down>" simple-mpc-next)

        ("<up>" simple-mpc-prev)

        ("<left>" simple-mpc-seek-backward)

        ("<right>" simple-mpc-seek-forward)

        ;; this is the default simple-mpc keybind
        ("c" simple-mpc-view-current-playlist :color blue)
        ("s" simple-mpc-query :color blue)
        ("t" simple-mpc-toggle)
        ("SPC" simple-mpc-toggle :color blue)

        ("q" nil :color blue))
        )))
rice no more.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Sat Apr 09, 2016 9:04 am

^ Interesting stuff. By the way, I've come the really appreciate hydra. Been using it for multiple cursors, yasnippets and smartparens.

User avatar
franksinistra
Ivana Fukalot
Posts: 1093
Joined: Mon Jan 27, 2014 2:03 am
Location: 印尼国

Re: Emacs tips and tricks

Unread post by franksinistra » Sat Apr 09, 2016 9:47 am

^ hydra is very cool, although i'm only scratching the surface now... i need to investigate more, thanks GP!
rice no more.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Sat Apr 09, 2016 9:51 am

^ np. For instance:

Code: Select all

(use-package multiple-cursors        ; Easily place multiple cursors in a buffer
  :ensure t
  :bind ("C-c o" . mu-multiple-cursors/body)
  :init
  (defhydra mu-multiple-cursors (:hint nil)
    "
Multiple cursors (quit with _q_)
^Mark^                ^Edit^              ^Other^
^----^----------------^----^--------------^-----^----------------------
_e_:   mark more      _l_:   edit lines   _a_: vertical align
_h_:   mark all       _C-a_: edit begs    _s_: set rect action
_n_:   mark next      _C-e_: edit ends
_p_:   mark previous
_r_:   mark regexp
_C-s_: mark region
"
    ("q" nil)
    ("a" mc/vertical-align :exit t)
    ("e" mc/mark-more-like-this-extended)
    ("h" mc/mark-all-like-this-dwim)
    ("l" mc/edit-lines :exit t)
    ("n" mc/mark-next-like-this)
    ("p" mc/mark-previous-like-this)
    ("r" vr/mc-mark)
    ("s" set-rectangular-region-anchor)
    ("C-a" mc/edit-beginnings-of-lines :exit t)
    ("C-e" mc/edit-ends-of-lines :exit t)
    ("C-s" mc/mark-all-in-region))
  :config
  (setq mc/mode-line
        ;; Simplify the MC mode line indicator
        '(:propertize (:eval (concat " " (number-to-string
                                          (mc/num-cursors))))
                      face font-lock-warning-face)))

User avatar
slartie
Grump
Posts: 416
Joined: Tue Jun 18, 2013 12:35 pm
Location: Denmark
Contact:

Re: Emacs tips and tricks

Unread post by slartie » Sat Apr 30, 2016 6:28 pm

Perhaps you're new to Emacs, or you find the keybindings a forbidding place that keeps you from ever diving in. There's help at your fingertips. Apart from going through the Emacs Tutorial ("C-h t" which means press and hold down the CTRL key and pressing h, releasing the key and pressing t), GNU also offers a handy cheat sheet.

https://www.gnu.org/software/emacs/refc ... efcard.pdf

If you find the GNU Emacs cheat sheet to be a bit too dry for your tastes, you might enjoy the wonderful Sacha Chua's creative illustration series.

http://sachachua.com/blog/series/a-visu ... -to-emacs/

I did a, for me at least, thorough search on the forums and couldn't find any mention of these two links, so I decided to throw them in here. Sacha's illustrations have a few years on them now, but in Emacs terms it's basically brand new.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Sun May 01, 2016 8:25 am

^ That's some awesome stuff. I've been using which-key for a while, now, and that can also be helpful for beginners.

User avatar
slartie
Grump
Posts: 416
Joined: Tue Jun 18, 2013 12:35 pm
Location: Denmark
Contact:

Re: Emacs tips and tricks

Unread post by slartie » Sun May 01, 2016 9:11 am

which-key is so damned useful - beginner or otherwise.

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

Re: Emacs tips and tricks

Unread post by GekkoP » Tue May 03, 2016 4:03 pm

Disabling mouse only in Emacs: http://endlessparentheses.com/disable-m ... emacs.html

I prefer disabling only the touchpad though, so, inspired by the comments in that blog post, I came up with this:

Code: Select all

(defun mu-touchpad-off ()
  "Disable touchpad using an external shell script.

It needs https://github.com/manuel-uberti/scripts/blob/master/touchpad-off
in `exec-path'.

Examples:
(add-hook 'focus-in-hook #'mu-touchpad-off)"
  (interactive)
  (let ((toff (executable-find "touchpad-off")))
    (unless toff
      (user-error "Shell script touchpad-off not found"))
    (with-temp-buffer
      (shell-command toff t))))

(defun mu-touchpad-on ()
  "Enable touchpad using an external shell script.

It needs https://github.com/manuel-uberti/scripts/blob/master/touchpad-on
in `exec-path'.

Examples:
(add-hook 'focus-out-hook #'mu-touchpad-on)
(add-hook 'delete-frame-functions #'mu-touchpad-on)"
  (interactive)
  (let ((ton (executable-find "touchpad-on")))
    (unless ton
      (user-error "Shell script touchpad-on not found"))
    (with-temp-buffer
      (shell-command ton t))))

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

Re: Emacs tips and tricks

Unread post by GekkoP » Mon May 09, 2016 7:19 pm

Better flyspell interface, completion-read agnostic: https://github.com/d12frosted/flyspell-correct

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

Re: Emacs tips and tricks

Unread post by GekkoP » Wed Jun 01, 2016 11:10 am

If your killing spree is too much to tame, you might find this useful.

Code: Select all

(defun mu-reopen-last-killed-buffer ()
  "Quickly reopen last killed buffer."
  (interactive)
  (find-file (car recentf-list)))

User avatar
slartie
Grump
Posts: 416
Joined: Tue Jun 18, 2013 12:35 pm
Location: Denmark
Contact:

Re: Emacs tips and tricks

Unread post by slartie » Fri Jun 03, 2016 1:12 pm

Smartparens is cool and all, but I don't want everything paired eeeeverywhere. In lisp dialects, the ' character usually stands alone, so let's stop pairing that one.

Code: Select all

(with-eval-after-load 'smartparens
  (sp-local-pair 'emacs-lisp-mode "'" nil :actions nil)
  (sp-local-pair 'lisp-interaction-mode "'" nil :actions nil)
  (sp-local-pair 'scheme-mode "'" nil :actions nil)
  (sp-local-pair 'inferior-scheme-mode "'" nil :actions nil))

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

Re: Emacs tips and tricks

Unread post by GekkoP » Fri Jun 03, 2016 4:42 pm

^ Weird, I did nothing and Smartparens is not automatically pairing the quote in my case. Althout I have this in my config:

Code: Select all

(dolist (hook '(inferior-emacs-lisp-mode-hook
                  emacs-lisp-mode-hook
                  scheme-mode-hook
                  clojure-mode-hook))
    (add-hook hook #'smartparens-strict-mode))

User avatar
slartie
Grump
Posts: 416
Joined: Tue Jun 18, 2013 12:35 pm
Location: Denmark
Contact:

Re: Emacs tips and tricks

Unread post by slartie » Fri Jun 03, 2016 5:03 pm

smartparens-strict-mode might be sorting that out for you, not sure.

User avatar
wuxmedia
Grasshopper
Posts: 5902
Joined: Wed Oct 17, 2012 11:32 am
Location: UK
Contact:

Re: Emacs tips and tricks

Unread post by wuxmedia » Tue Jun 07, 2016 2:13 pm

Don't use old muscle memory and hit 'ctrl-z' to undo, otherwise...
Mark set....
hangs for like 5 mins...

What is that anyway like some sort of punishment?
"Seek, and Ye shall find"
"Github | Chooons | Site"

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

Re: Emacs tips and tricks

Unread post by GekkoP » Tue Jun 07, 2016 2:21 pm

When in doubt, ask Emacs. :)
In this case: C-h k C-z.

Then, if you wish: (global-set-key (kbd "C-z") 'undo)

User avatar
wuxmedia
Grasshopper
Posts: 5902
Joined: Wed Oct 17, 2012 11:32 am
Location: UK
Contact:

Re: Emacs tips and tricks

Unread post by wuxmedia » Tue Jun 07, 2016 8:09 pm

^ Ahh right, thanks. I suppose that is 'shell-like' behaviour :)
wouldn't do it if it was in the terminal...
"Seek, and Ye shall find"
"Github | Chooons | Site"

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

Re: Emacs tips and tricks

Unread post by GekkoP » Mon Aug 22, 2016 8:33 pm


machinebacon
Baconator
Posts: 10234
Joined: Thu Sep 16, 2010 11:03 am
Location: Chinkistan
Contact:

Re: Emacs tips and tricks

Unread post by machinebacon » Sun Sep 18, 2016 7:41 am

Was about time: integration of xwidgets (and thus, webkit)

https://www.youtube.com/watch?v=J2YdjpWJJHs
..gnutella..

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

Re: Emacs tips and tricks

Unread post by GekkoP » Sun Sep 18, 2016 11:31 am

Schema validation for your lovely Emacs setup? Yes, please

https://manuel-uberti.github.io/emacs/2 ... /validate/

(oh wait, I know that guy. He's a good one, trust him.)

Post Reply