Skip to content

Commit

Permalink
expose macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Apr 21, 2024
1 parent 4748722 commit 98663ba
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions mbs.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,44 @@

(require 's)

(defmacro mbs--with-minibuffer-env (&rest body)
;;
;;; Util

;;;###autoload
(defmacro mbs-with-minibuffer-env (&rest body)
"Execute BODY with minibuffer variables."
(declare (indent 0) (debug t))
`(let ((prompt (minibuffer-prompt))
(contents (minibuffer-contents)))
,@body))

;;
;;; Core

;;;###autoload
(defun mbs-M-x-p ()
"Return non-nil if current minibuffer `M-x'."
(mbs--with-minibuffer-env
(mbs-with-minibuffer-env
(string-prefix-p "M-x" prompt)))

;;;###autoload
(defun mbs-finding-file-p ()
"Return non-nil if current minibuffer finding file."
(mbs--with-minibuffer-env
(mbs-with-minibuffer-env
(and (not (mbs-M-x-p))
(not (string-empty-p contents))
(ignore-errors (expand-file-name contents)))))

;;;###autoload
(defun mbs-renaming-p ()
"Return non-nil if current minibuffer renaming."
(mbs--with-minibuffer-env
(mbs-with-minibuffer-env
(string-prefix-p "New name:" prompt)))

;;;###autoload
(defun mbs-tramp-p ()
"Return non-nil if current minibuffer connect over tramp."
(mbs--with-minibuffer-env
(mbs-with-minibuffer-env
(and (mbs-finding-file-p)
(s-contains-p ":" contents)
(string-prefix-p "/" contents))))
Expand Down

0 comments on commit 98663ba

Please sign in to comment.