Switch-buffer: Longer buffer list

I would like to see a longer buffer list when I run switch-buffer. Actually, I would like to change two things:

  1. In the switch-buffer mode, I want to see only the “Buffer list” but no “Create new buffer” list. I could change this by commenting out (make-instance 'new-url-or-search-source ...) in buffer.lisp and recompiling. Is there an easier way to achieve this? Is there a configuration slot for this? Or can I overwrite the whole (define-command switch-buffer ...) in my config.lisp?
  2. Removing the “Create new buffer” list doesn’t help because the buffer list doesn’t use the whole available space:

    It shows only 8 of 16 buffers. Can I configure this to use the full space?

You can configure it, but not easily. This is actually a long standing issue we have with how the prompt buffer writes HTML. We don’t know how many entries to draw because we don’t know how tall the prompt buffer will be. We could theoretically calculate it, and we probably should. I have been thinking for years about how to solve this. I have some ideas. To see more about this in the source you can take a look at the prompt-buffer.lisp file.

Thank you! I have changed this 8 to 24:

(loop
  ;; TODO: calculate how many lines fit in the prompt buffer
  with max-suggestion-count = 24
  repeat max-suggestion-count

This works well. Even when there are multiple suggestion sources. I guess the only drawback is some wasted CPU time when the loop processes more entries than can be shown.

I’ll try to figure out how to calculate this number.

@MaxGyver83 let me answer your first question from the top post.

First of all, I have opposed the inclusion of "Create new buffer" in the switch-buffer. See buffer(switch-buffer): Add a source to create a new buffer. by aartaka · Pull Request #3024 · atlas-engineer/nyxt · GitHub.

Nyxt is meant to be used by non-programmers. Making a change and recompiling it is an option for the able ones (like you), but there should always be a user-friendly way. If it doesn’t, then please report it since it’s a sign we need to improve.

In this particular case, you can write a modified version of switch-buffer in your config file. Since your config file is the last piece of code that is evaluated and commands are methods, the command will be redefined. That’s why you’ll see WARNING: redefining NYXT:SWITCH-BUFFER in DEFGENERIC when starting Nyxt.

The only thing that you need to take into account is that its definition may use symbols that are not exported, so you’ll need to prepend those with nyxt::. In this case, buffer-initial-suggestions became nyxt::buffer-initial-suggestions.

(define-command switch-buffer (&key buffer (current-is-last-p nil))
  "Switch buffer using fuzzy completion.
Buffers are ordered by last access.
With CURRENT-IS-LAST-P, the current buffer is listed last so as to list the
second latest buffer first."
  (if buffer
      (set-current-buffer buffer)
      (prompt :prompt "Switch to buffer"
              :sources (make-instance 'buffer-source
                                      :constructor (nyxt::buffer-initial-suggestions
                                                    :current-is-last-p current-is-last-p)))))

Thank you for your answer! It’s good to know that overwriting functions is an option and that I have to take care to get the namespaces (packages) right.

This link to PR #3024 is also helpful: Now I understand why “Create new buffer” was added to switch-buffer at all.

If you say that Nyxt is also meant for non-programmers (“the hacker’s browser” doesn’t sound like that :slight_smile:), then a simple (bool) option to disable the “Create new buffer” source would be even better than adding this macro call to the config.

@MaxGyver83 Nyxt is meant for knowledge workers, since there are non-programmers who require advanced programs. Broadly speaking, hackers are frequently programmers but not always. Think of someone doing really serious investigation journalism.

1 Like