diff --git a/README.org b/README.org index a13b591..07840b8 100644 --- a/README.org +++ b/README.org @@ -11,9 +11,22 @@ file organization suggests. *** Corfu **** clean up orderless **** integrate with yasnippets -** eshell/emacs +** eshell/emacs DWIM +CONTROL FLOW +#+begin_quote +1. Check arguments + 1. No args: run new Emacs instance, separate frame, windowed + 2. existing file names: open each in new buffer (`find-file`?) ?(and window)? + 1. non-existent file names + 1. if name of library, edit that library + 1. otherwise edit new file of that name in default-directory + 3. dash options + 1. =-nw=​: open in same window + 2. =--client=​: use =emacsclient= instead of =emacs= + 3. Pass rest of options to exe +#+end_quote *** /usr/bin/emacs or emacsclient fallback for options -*** find-library etc +*** DONE find-library etc ** eshell/dat *** fix naming and loading *** "bcat" diff --git a/lisp/mitch-packages.el b/lisp/mitch-packages.el index 710c7b2..258d839 100644 --- a/lisp/mitch-packages.el +++ b/lisp/mitch-packages.el @@ -158,12 +158,28 @@ "Basically you can edit ARGS and it will open in a new buffer. When your shell is Emacs, your Emacs is but an oyster... This is taken from a website that I can't remember at the moment." - (if (null args) (bury-buffer) - (let ((open-func (if (one-window-p) - #'find-file-other-window - #'find-file))) - (mapc open-func - (mapcar #'expand-file-name (flatten-tree (reverse args))))))) + (let* ((exe (if (member "--client" args) + (executable-find "emacsclient") + (executable-find "emacs"))) + (args (remove "--client" args)) + (openfun (lambda (arg) + (let ((arg-file-name (expand-file-name arg)) + (arg-lib-name (locate-library arg))) + (if (file-exists-p arg-file-name) + (funcall find-fun arg-file-name) + (if arg-lib-name + (funcall lib-fun arg) + (funcall find-fun arg-file-name))))))) + (if (and (one-window-p) (not (member "-nw" args))) + (setq find-fun #'find-file-other-window + lib-fun #'find-library-other-window) + (setq find-fun #'find-file + lib-fun #'find-library)) + (setq args (remove "-nw" args)) + (if (null args) + (async-shell-command exe) + (mapcar openfun + (flatten-tree (reverse args)))))) (defun mitch/eshell-setup-keys () (evil-collection-define-key 'normal