* Whats the idiomatic way to erase a buffer?
@ 2019-12-10 14:08 Mario Lang
2019-12-10 14:17 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Mario Lang @ 2019-12-10 14:08 UTC (permalink / raw)
To: emacs-devel
Hi.
I am using:
(defun my-func (name)
(with-current-buffer (get-buffer-create name)
(let ((inhibit-read-only t))
(erase-buffer))
(my-special-mode)
...
(switch-to-buffer (current-buffer)))
my-special-mode uses widget-browse-mode as parent.
When I bury the buffer with 'q' and create the same
buffer, 'q' now complains:
Text is read-only: "Attempt to change text outside editable field"
So something else must be missing.
my-special-mode is supposed to run kill-all-local-variables, AFAICT.
Is there anything else I should do to ensure that the buffer
content is really forgotten about.
Or should I be using kill-buffer? Likely not, because it
would tinker with my window-configuration...
Help would be appreciated
--
CYa,
⡍⠁⠗⠊⠕
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Whats the idiomatic way to erase a buffer?
2019-12-10 14:08 Whats the idiomatic way to erase a buffer? Mario Lang
@ 2019-12-10 14:17 ` Stefan Monnier
2019-12-10 14:48 ` T.V Raman
2019-12-10 17:47 ` Mario Lang
0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2019-12-10 14:17 UTC (permalink / raw)
To: Mario Lang; +Cc: emacs-devel
> (defun my-func (name)
> (with-current-buffer (get-buffer-create name)
> (let ((inhibit-read-only t))
> (erase-buffer))
That look OK.
> When I bury the buffer with 'q' and create the same
> buffer, 'q' now complains:
>
> Text is read-only: "Attempt to change text outside editable field"
I think you want to M-x toggle-debug-on-error RET, then reproduce the
bug so we can see the backtrace which will hopefully clarify what's
going on. It may be that the buffer has overlays that survive the
erasure (as 0-length overlays) and then re-grow as text is inserted.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Whats the idiomatic way to erase a buffer?
2019-12-10 14:17 ` Stefan Monnier
@ 2019-12-10 14:48 ` T.V Raman
2019-12-10 17:47 ` Mario Lang
1 sibling, 0 replies; 5+ messages in thread
From: T.V Raman @ 2019-12-10 14:48 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Mario Lang, emacs-devel
I think he needs to lexically bind inhibit-read-only to t
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Whats the idiomatic way to erase a buffer?
2019-12-10 14:17 ` Stefan Monnier
2019-12-10 14:48 ` T.V Raman
@ 2019-12-10 17:47 ` Mario Lang
2019-12-10 18:15 ` Mario Lang
1 sibling, 1 reply; 5+ messages in thread
From: Mario Lang @ 2019-12-10 17:47 UTC (permalink / raw)
To: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (defun my-func (name)
>> (with-current-buffer (get-buffer-create name)
>> (let ((inhibit-read-only t))
>> (erase-buffer))
>
> That look OK.
>
>> When I bury the buffer with 'q' and create the same
>> buffer, 'q' now complains:
>>
>> Text is read-only: "Attempt to change text outside editable field"
>
> I think you want to M-x toggle-debug-on-error RET, then reproduce the
> bug so we can see the backtrace which will hopefully clarify what's
> going on.
It is not an error I'm afraid.
First time around, C-h k q gives me
q runs the command bury-buffer (found in sclang-scdoc-mode-map)
but the second time around I get
q runs the command self-insert-command (found in global-map)
However, major-mode evalutes to sclang-scdoc-mode in both cases.
And sclang-scdoc-mode is defined as:
(defvar sclang-scdoc-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map widget-browse-mode-map)
(define-key map (kbd "C-c C-f") #'sclang-scdoc-find-schelp)
(define-key map (kbd "C-c C-h") #'sclang-find-scdoc)
(define-key map (kbd "C-c C-s") #'sclang-main-stop)
(define-key map (kbd "C-c C-w") #'sclang-switch-to-workspace)
(define-key map (kbd "C-M-x") 'sclang-eval-defun)
map))
(define-derived-mode sclang-scdoc-mode widget-browse-mode "SCDoc"
"Major mode for displaying SuperCollider Documentation."
(sclang-init-document)
(sclang-make-document))
> It may be that the buffer has overlays that survive the erasure (as
> 0-length overlays) and then re-grow as text is inserted.
Since I am using `widget-create' a lot, that might be a possibility.
How do I eliminate overlays in a buffer?
--
CYa,
⡍⠁⠗⠊⠕
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Whats the idiomatic way to erase a buffer?
2019-12-10 17:47 ` Mario Lang
@ 2019-12-10 18:15 ` Mario Lang
0 siblings, 0 replies; 5+ messages in thread
From: Mario Lang @ 2019-12-10 18:15 UTC (permalink / raw)
To: emacs-devel
Mario Lang <mlang@delysid.org> writes:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> It may be that the buffer has overlays that survive the erasure (as
>> 0-length overlays) and then re-grow as text is inserted.
>
> Since I am using `widget-create' a lot, that might be a possibility.
> How do I eliminate overlays in a buffer?
Nevermind, `delete-all-overlays' did the trick.
Thanks for the hint!
--
CYa,
⡍⠁⠗⠊⠕
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-12-10 18:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-10 14:08 Whats the idiomatic way to erase a buffer? Mario Lang
2019-12-10 14:17 ` Stefan Monnier
2019-12-10 14:48 ` T.V Raman
2019-12-10 17:47 ` Mario Lang
2019-12-10 18:15 ` Mario Lang
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.