Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crux-start-or-switch-to #25

Open
ury-marshak opened this issue Mar 30, 2016 · 1 comment
Open

crux-start-or-switch-to #25

ury-marshak opened this issue Mar 30, 2016 · 1 comment

Comments

@ury-marshak
Copy link

When trying to use crux-start-or-switch-to with slime-connect function there is problem that slime-connect names its buffer according to the type of common lisp implementation that it connected to, so the resulting buffer can be named "slime-repl sbcl", "slime-repl ccl" etc. I slightly changed the function, adding a helper get-buffer-extended function:

(defun get-buffer-extended (buffer-name &optional match)
"Finds a buffer by its name. If the optional parameter MATCH is then call the standard
GET-BUFFER, if MATCH is :PREFIX, then it looks for buffers with names starting with BUFFER-NAME
and returns the first one that matches. When MATCH is :REGEXP does the same but BUFFER-NAME
is a regular expression."
    (cond ((null match) (get-buffer buffer-name))
          ((eq match :regexp)
           (catch 'done
             (dolist (buffer (buffer-list))
               (let ((name (buffer-name buffer)))
                 (when (string-match buffer-name name)
                   (throw 'done buffer))))))
          ((eq match :prefix)
           (catch 'done
             (dolist (buffer (buffer-list))
               (let ((name (buffer-name buffer)))
                 (when (string-prefix-p buffer-name name)
                   (throw 'done buffer))))))))

  (defun start-or-switch-to (function buffer-name &optional match)
    "Modified crux-start-or-switch-to from https://github.com/bbatsov/crux/blob/master/crux.el
  Add MATCH parameter that can be :prefix to find any buffer that starts with BUFFER-NAME or
  :REGEXP to use regular expressions in the search string."
    (let ((buf (get-buffer-extended buffer-name match)))
      (if (not buf)
          (progn
            (split-window-sensibly (selected-window))
            (other-window 1)
            (funcall function))
        (switch-to-buffer-other-window buf))))

There probably are other cases like this, where the names of the buffers can vary, so maybe such generalization may be of use.

@bbatsov
Copy link
Owner

bbatsov commented Apr 5, 2016

Yeah, you're probably right. I'm a bit busy these days but I'll think a bit more about this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants