Whats the idiomatic way to erase a buffer?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Whats the idiomatic way to erase a buffer?

Mario Lang
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,
  ⡍⠁⠗⠊⠕

Reply | Threaded
Open this post in threaded view
|

Re: Whats the idiomatic way to erase a buffer?

Stefan Monnier
> (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


Reply | Threaded
Open this post in threaded view
|

Re: Whats the idiomatic way to erase a buffer?

T.V Raman
I think he needs to  lexically bind inhibit-read-only to t
--

Reply | Threaded
Open this post in threaded view
|

Re: Whats the idiomatic way to erase a buffer?

Mario Lang
In reply to this post by Stefan Monnier
Stefan Monnier <[hidden email]> 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,
  ⡍⠁⠗⠊⠕

Reply | Threaded
Open this post in threaded view
|

Re: Whats the idiomatic way to erase a buffer?

Mario Lang
Mario Lang <[hidden email]> writes:

> Stefan Monnier <[hidden email]> 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,
  ⡍⠁⠗⠊⠕