[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Must prevent switching from recursive edit buffers
From: |
Jean Louis |
Subject: |
Re: Must prevent switching from recursive edit buffers |
Date: |
Sat, 21 Dec 2024 20:38:20 +0300 |
User-agent: |
Mutt/2.2.12 (2023-09-09) |
* Stefan Monnier <monnier@iro.umontreal.ca> [2024-12-21 18:24]:
> > That is some mystery. Those recursive-edit buffers show as
> >
> > [[[[[(Mail WK Fill)]]]]]
> >
> > but I cannot know in the list of buffer and CANNOT SEE to what buffers
> > those [[[[]]]] belogns.
>
> Hmm... currently I think that Emacs's code does not record a clear
> association between a recursive edit and "the buffer to which it
> belongs" (arguably even this concept is ill-defined, although in
> practice it is probably true that there is almost always a buffer with
> which we can associate the recursive edit).
>
> Maybe we could start by implementing a command which shows a list of
> current recursive edits by walking the backtrace and trying to guess
> which "kind" of recursive edit it is and to which buffer is
> "belongs".
That is missing, thanks for recognizing the lack of logic.
> Kinds would be things like `minibuffer`, `debugger`, `edebug`,
> `query-replace`, ...
But in my work they have always names. My recursive buffer opens full
screen like any other.
I understand someone or you, made similar function, but I don't like
it, so I use this function below.
(defun read-from-buffer (&optional value buffer-name mode title keymap place
highlight-list minor-modes input-method)
"Return string after editing it in buffer."
(let* ((this-buffer (buffer-name))
(title (or title ""))
(value (or value ""))
(new-value value)
(point (cond ((numberp place) place)
((listp place) (cdr (assoc "place" place)))))
(table (when (listp place) (cdr (assoc "table" place))))
(column (when (listp place) (cdr (assoc "column" place))))
(table-id (when (listp place) (cdr (assoc "table-id" place))))
(buffer-name (or buffer-name "*RCD String Editing*"))
(buffer-name (concat buffer-name " 🗒️"))
;; (my-buffer-kill-hook kill-buffer-hook)
(read-buffer (get-buffer-create buffer-name)))
(with-current-buffer read-buffer
(switch-to-buffer read-buffer)
(erase-buffer)
(cond (mode (if (fboundp mode)
(funcall mode)
(rcd-message "You need `%s' mode" (symbol-name mode))))
(t (text-mode)))
(setq rcd-db-current-table table)
(setq rcd-db-current-column column)
(setq rcd-db-current-table-id table-id)
(local-set-key (kbd "<f8>") 'exit-recursive-edit)
(local-set-key (kbd "C-c A") 'abort-recursive-edit)
;; total mess
;; (setq-local kill-buffer-hook (append kill-buffer-hook
;; (list
;; (lambda ()
;; (setq-local
kill-buffer-hook my-buffer-kill-hook)
;; (kill-buffer read-buffer)
;; (cond ((>
(recursion-depth) 0) (exit-recursive-edit)))))))
(when keymap
(use-local-map keymap))
(when input-method (set-input-method input-method))
(when rcd-word-processing
(rcd-word-processing))
(setq header-line-format (format "%s ➜ Finish editing with or C-M-c or
F8" title))
(if (stringp value) (insert value))
(rcd-highlight-list highlight-list)
(goto-char (or point (point-min)))
(rcd-speak "You may quit the buffer with Meta Control C")
(message "When you're done editing press C-M-c or F8 to continue.")
(setq eval-expression-debug-on-error nil)
(while minor-modes
(let ((minor-mode (pop minor-modes)))
(if minor-mode
(if (fboundp (intern minor-mode))
(funcall (intern minor-mode))
(rcd-message "You need `%s' minor mode" (symbol-name
minor-mode))))))
(unwind-protect
(recursive-edit)
(if (get-buffer-window read-buffer)
(progn
(setq new-value (buffer-substring (point-min) (point-max)))
(kill-buffer read-buffer))))
(setq eval-expression-debug-on-error t)
(prog1 new-value
(switch-to-buffer this-buffer))))) ;; TODO if mode is used, maybe it
should not return propertized string
> That would have to rely on ad-hoc rules, but that would give us some
> experience from which we could hopefully design a better API which ELisp
> packages which use `recursive-edit` can then use to provide that same
> information more directly.
My buffers open up in full window. Each of them has a name.
They are immediately available in the buffer list.
But I cannot know yet why, they also disappear, so I am left with
[[[[]]]] and do not know to what it belongs.
Then I go to the buffer list and I can start deleting buffers, but
have no idea which one is in recursive-edit, so sometimes I get
result:
- I have deleted buffers, and recursive edits are also resolved;
- sometimes I have deleted it and [[[[]]]] still remain on the
modeline; and I have no idea why;
And I am still confused, maybe I am wrong about it in general.
--
Jean Louis