I added an embark config from: https://karthinks.com/software/fifteen-ways-to-use-embark/#open-any-buffer-by-splitting-any-window, which works really good, the only problem is that if a file is opened with project-find-file-in, it doesn’t respect its own directory.

Steps:

  1. When the default-directory set to ~/, M-x browse-emacs-config to open a file list of ~/.config/emacs in the minibuffer
  2. embark-act on a file lisp/init-lib.el
  3. o and b to open the selected file horizontally
  4. A buffer opened on the right side, but the directory is still using the default-directory in step 1 instead of the buffer’s directory, causing the buffer to visit ~/lisp/init-lib.el instead of ~/.config/emacs/lisp/init-lib.el.

Config:

(defun find-file-in-project (&optional dir)
  (interactive)
  (let ((project (project-current nil dir)))
    (project-find-file-in nil nil project)))

(defun browse-emacs-config ()
  (interactive)
  (find-file-in-project "~/.config/emacs"))

(eval-when-compile
  (defmacro my/embark-aw-action (fn)
    `(defun ,(intern (concat "my/embark-aw-" (symbol-name fn))) ()
       ,(format "Open %s buffer selected with ace-window" (symbol-name fn))
       (interactive)
       (with-demoted-errors "%s"
         (require 'ace-window)
         (let ((aw-dispatch-always t))
           (aw-switch-to-window (aw-select nil))
           (call-interactively (symbol-function ',fn)))))))

(define-key embark-file-map (kbd "o") (my/embark-aw-action find-file))
  • goofansu@alien.topOPB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Thank you! You’re right, the scope is not transformed, set default-directory in the middle function works.