Function: dape-watch-dwim

dape-watch-dwim is an interactive and natively compiled function defined in dape.el.

Signature

(dape-watch-dwim EXPRESSION &optional REMOVE-ONLY-P ADD-ONLY-P DISPLAY-P)

Documentation

Toggle watch for EXPRESSION.

When called interactively the EXRPRESSION defaults to symbol at point or active region. If REMOVE-ONLY-P is non-nil only allow removal of an existing watch. If ADD-ONLY-P is non-nil only allow adding a new watch. If DISPLAY-P is non-nil display-p the watch buffer.

Key Bindings

ctl-x-map C-a w dape-global-map w global-map C-x C-a w help-quick-use-map C-x C-a w

Source Code

;; Defined in /nix/store/1fiaif8pifqj2jh65rbg3fkhg3i56q42-emacs-packages-deps/share/emacs/site-lisp/elpa/dape-0.27.1/dape.el
(defun dape-watch-dwim (expression &optional remove-only-p add-only-p display-p)
  "Toggle watch for EXPRESSION.
When called interactively the EXRPRESSION defaults to symbol at point
or active region.
If REMOVE-ONLY-P is non-nil only allow removal of an existing watch.
If ADD-ONLY-P is non-nil only allow adding a new watch.
If DISPLAY-P is non-nil display-p the watch buffer."
  (interactive
   (let* ((map (copy-keymap minibuffer-local-completion-map))
          (minibuffer-local-completion-map map)
          (default (or (and (region-active-p)
                            (buffer-substring (region-beginning) (region-end)))
                       (thing-at-point 'symbol))))
     (define-key map " " #'self-insert-command)
     (define-key map "?" #'self-insert-command)
     (list (string-trim
            (completing-read
             (format-prompt "Toggle watch of expression" default)
             (mapcar (lambda (plist) (plist-get plist :name)) dape--watched)
             nil nil nil nil default))
           nil nil t)))
  (if-let* ((watched
             (cl-find expression dape--watched
                      :key (lambda (plist) (plist-get plist :name))
                      :test #'equal)))
      (unless add-only-p
        (setq dape--watched (cl-delete watched dape--watched)))
    (unless remove-only-p
      (push (list :name expression) dape--watched)))
  (when display-p
    (dape--display-buffer (dape--info-get-buffer-create 'dape-info-watch-mode)))
  (run-hooks 'dape-update-ui-hook))