This put me off Kakoune for a long time:
kak:qAnd you lose the whole lot! Now I understand that *scratch* is designed to be lost, but this will definitely burn people, as most other editors don't delete data this readily. Emacs solves this by adding text at the beginning of *scratch*:
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
But I'd suggest copying vim, and opening a non-scratch unsaved buffer by default.
I like the current design and get annoyed when using vi(m) and cannot just :q in some usecases. however you can set an alias in your shell: alias k='kak newfile'
Maybe going the emacs route is a viable option to improve the user experience.
related #2360 & #1496
I'd also wanted *scratch* to be something like a buffer for kakscript evaluation, similar to Emacs' *scratch*. I really love that in Emacs you can fire up a scratch buffer, write some Emacs Lisp in it, and evaluate it. This is certainly doable with Kakoune's source %val{buffile} but it requires a file to do evaluation. It's extremely useful when you want to quicly define a command or a hook, without using singleline prompt mode
map global user s -docstring 'Evaluate the main selection' ':<c-r>.<ret>'
map global user S -docstring 'Evaluate the current buffer' '%:<c-r>.<ret>'
Thanks, @alexherbo2. That's a nice addition to my configuration
@mawww I preferred the scratch buffer being empty.
hook -always -once global WinCreate '\Q*scratch*' %{
hook -always -once window InsertEnd '' %{
info -title 'Information' %[
This is a *scratch* buffer which won鈥檛 be automatically saved.
Use it for notes or open a file buffer with the :edit command.
]
}
}
can I delete *scratch* automatically if no changes were made to it and another file was opened?
*scratch*, *debug*file, *debug*Or:
*scratch*, *debug*file, *scratch*, *debug*@andreyorst I've got this in my kakrc that pretty much does it
# delete the *scratch* buffer as soon as another is created, but only if it's empty
hook global BufCreate '^\*scratch\*$' %{
hook -once -always global BufCreate '^(?!\*scratch\*).*$' %{
try %{
# throw if the buffer has more than one character
exec -buffer *scratch* 'L<a-K>..<ret>'
db *scratch*
}
}
}
Likely needs to be updated now that *scratch* contains default text
The scratch buffer being populated with text feels like my buffer is dirty.
The scratch buffer being populated with text feels like dirty.
I think that the default text should be configured via option, much like in Emacs. I don't use default text there, but some people may do.
I've got this in my kakrc that pretty much does it
That's clever. Added this to my kakrc, thanks!
I don鈥檛 agree on the direction taken to solve this issue.
The root of the issue was not the scratch feature by itself, but filling a scratch buffer to edit a new document when no explicit file-name was given.
@alexherbo2 I agree it is not very satisfying, there is a already a [scratch] marker in the mode line, but this is an issue that comes back regularly and I figured that would make new comers more aware of the semantics of scratch buffers in Kakoune.
Happy to revisit if we find a better way to make scratch buffer behaviour more obvious (I think the scratch buffer behaviour is sane, but newcomers do not know what to expect from them and get confused that what they have typed in it gets lost with no warning).
@mawww How about https://github.com/mawww/kakoune/issues/1496#issuecomment-473907027
I think that the default text should be configured via option, much like in Emacs. I don't use default text there, but some people may do.
I agree, this way it is on by default, but easy to turn off, just like a lot of other settings (clippy comes to mind)
Most helpful comment