Fork me on GitHub

I had somebody email me describing some pain around using windows and buffers. He was asking for tips, so I wrote some. I thought I'd share them here in case they're useful to anybody else. > 1. SPC w u for winner-undo, which undoes the last change to windows. > 2. SPC TAB to go to the previous buffer visited by a window. > 3. Using layouts. It took me a while to learn how to do this effectively, but I currently have a separate layout e.g. for viewing my org-mode files and agenda. I visit that layout to plan my day (and revisit it occasionally during the day), which I can do and then go back to the previous layout when I'm done, which saves the window arrangement I had before I switched to that layout. One potentially confusing thing: when you're in any non-default layout, not all buffers are available in that layout. You have to add them to the layout explicitly, with SPC l a I think. > 4. SPC 1 through SPC <n> to switch to a window by number. I usually have windows arranged strictly as columns (i.e. without multiple windows in a single column), which helps this be more useful. > 5. SPC w TAB to switch to the previous window. > 6. SPC t g to toggle golden ratio mode, which I find to be nice when I'm on my laptop screen but not when I'm on a bigger monitor. Sometimes things get a bit wonky in Spacemacs when toggling golden ratio on and off, which I've found I can fix by e.g. switching to the left-most window with SPC 1 then moving it to the left-most position (which you'd expect to be a no-op) with SPC w H. > > Also, I'll mention that, coming from vim, it took me a while to get used to editing without tabs, which I used a lot in vim. I briefly explored tab packages in emacs but didn't find anything I liked. I still use tabs when I use vim on the command line, but I've gotten pretty comfortable with spacemacs' way of doing this, like the things I mention above as well as SPC b b for fuzzy-finding a buffer by name.


I decided to also share this with the Spacemacs subreddit so the content would endure beyond ~4 days. simple_smile Here's a link: Interestingly, r/Clojure is listed as one of 5 subreddits related to r/Spacemacs. :thinking_face:


@jeff.terrell Thanks for the tips! I didn’t know about golden ratio mode


also it’s worth mentioning the windmove package. Navigating windows via Shift - Arrow Key


@alexkeyes - You're welcome! And I'll have to check that out. Feel free to add a comment to the post in Reddit if you like.


The default way to eval a clojure form with cider is to move the cursor past the closing paren of the form and hit , e e. I find that kind of annoying, because with vim bindings the cursor can only move to the last character of a line, not the character after it. I dunno if anybody else would find this useful, but I added a binding for ";" that lets me execute the form by putting my cursor on the first character of the form (the open paren). I did this by adding these two lines to my dotspacemacs/user-config

(evil-define-key 'normal clojurescript-mode-map ";" 'cider-eval-sexp-at-point)
(evil-define-key 'normal clojure-mode-map ";" 'cider-eval-sexp-at-point)


This is super useful in conjunction with another shortcut I defined for avy-goto-char. If I want to move my cursor really quickly to an open-paren, I just have to type g (, and type in the characters that appear on top of that paren.

(define-key evil-normal-state-map "g("  (defun go-to-paren () (interactive) (avy-goto-char ?\()))
(define-key evil-normal-state-map "g["  (defun go-to-bracket () (interactive) (avy-goto-char ?\[)))
(define-key evil-normal-state-map "g{"  (defun go-to-curly () (interactive) (avy-goto-char ?\{)))
(define-key evil-normal-state-map "g\"" (defun go-to-double () (interactive) (avy-goto-char ?\")))
(define-key evil-normal-state-map "g\'" (defun go-to-single () (interactive) (avy-goto-char ?\')))


You can also do this, @bfay, in order to have an eval operator that works the same way that eg d does:

;; Define an "eval" operator
    (evil-define-operator generic-evil-eval-operator (beg end)
      (cider-eval-region beg end))
    (define-key evil-normal-state-map (kbd (left-mod "e")) 'generic-evil-eval-operator)


(Except the left-mod thing is just something of mine, you'd want something like "A-e" or whatever)


Oh that's really cool, you're eval'ing the region that you encounter from your vim motion?


Yep. It's been a bit inconsistent for me, it sometimes has off-by-one errors where you only select up to the closing paren instead of up-to-and-including. But mostly it works pretty well 🙂


Thanks for the tip!


Anyone here have success integrating re-jump.el with spacemacs?


using spacemacs has left me an emacs newb, so I don’t know what to do with .el files, and I don’t know how to remap to something evily


@reefersleep - I'm no expert on such things, but I think what I'd try is, in my dotspacemacs/user-config in ~/.spacemacs, adding that code to whatever appropriate hook that I could find in clojure-mode or cider-mode. Let me know if that's not enough to go on…


Thanks @jeff.terrell 🙂 It’s not quite enough for my level of elisp-competence (near nil). I’m afraid of polluting my ~/.spacemacs with hacky junk, so I’d like to be more sure about what to do


Is it something like

(with-eval-after-load 'cider
(defun re-frame-jump-to-reg ()
  (let* ((kw (cider-symbol-at-point 'look-back))
         (ns-qualifier (and
                        (string-match "^:+\\(.+\\)/.+$" kw)
                        (match-string 1 kw)))
         (kw-ns (if ns-qualifier
                    (cider-resolve-alias (cider-current-ns) ns-qualifier)
         (target-file (concat (clojure-project-dir) (cider-sync-request:ns-path kw-ns)))
         (kw-to-find (concat "::" (replace-regexp-in-string "^:+\\(.+/\\)?" "" kw)))
         (buffer (cider--find-buffer-for-file target-file)))

    (when (and ns-qualifier (string= kw-ns (cider-current-ns)))
      (error "Could not resolve alias \"%s\" in %s" ns-qualifier (cider-current-ns)))
    (if buffer
        (progn (cider-jump-to buffer)
               (search-forward-regexp (concat "reg-[a-zA-Z-]*[ \\\n]+" kw-to-find) nil 'noerror))
      (error "Could not open a buffer for %s" target-file))))
(global-set-key (kbd "M->") 're-frame-jump-to-reg))


Maybe with something like (evil-define-key 'normal clojurescript-mode-map "G" 'reframe-jump-to-reg) (obviously with a different key. Should really be a SPC something something binding)


Without actually trying it myself, that looks very plausible to me. 👍 If you try it and have problems feel free to shout out.