1

I'm using menu-choice elisp widgets, and I find that a newline is inserted after each one, unlike say an editable-field widget.

I would like to place multiple menu-choice widgets side-by-side (like a kind of very simple menu bar), like so:

Menu: Value Menu: Value Menu: Value

Is this possible?

EDIT: here's an example of two widgets that print on two separate lines that it'd like to print on the same line:

(defun lem-ui-return-widgets (list)
  "Return a list of item widgets for each item, a string, in LIST."
  (cl-loop for x in list
           collect `(item :tag ,x :value ,x)))

(defun lem-ui-widget-format (str &optional binding)
  "Return a widget format string for STR, its name."
  (concat "%[" (propertize str 'face 'lem-ui-widget-face)
          "%]: %v"
          binding))

;; then in a display function:
;; (these two widgets print on separate lines,
;; regardless of whether a format function is used or not)
(widget-create 'menu-choice
               :tag "Listing"
               :value type
               :args (lem-ui-return-widgets lem-listing-types)
               :help-echo "Select a listing type"
               :format (lem-ui-widget-format "Listing" "C-c C-c")
               :notify (lem-ui-widget-notify-fun :sort))
(widget-create 'menu-choice
               :tag "Sort"
               :value sort
               :args (lem-ui-return-widgets lem-sort-types)
               :help-echo "Select a sort type"
               :format (lem-ui-widget-format "Sort" "C-c C-s")
               :notify (lem-ui-widget-notify-fun :listing-type))

(widget-minor-mode)

Also, when providing a formatting function, with the aim of adding some some text after the "%v" (value), I find that it also adds a newline following the value itself. Is it possible to add text after the %v on the same line?

like so: Menu: Value [C-c C-c]

my very simple format function (also from edit above):

(defun lem-ui-widget-format (str &optional binding)
  "Return a widget format string for STR, its name."
  (concat "%[" (propertize str 'face 'lem-ui-widget-face)
          "%]: %v"
          binding))

EDIT: the "binding" arg in the above, which I hand something like "C-c C-c" to, also prints on a separate line, below the widget that I am formatting. I would like it to be beside the widget.

EDIT 2: moreover, if i remove "%v" from the format function, i am able to print the two menu-choice widgets on the same line, so it looks like the "%v" is the cause of the both the issues i am describing.

String-trim doesn't work here, as it is only once the value is inserted into the format string that the newline is added.

2
  • Can you show us a complete example of what you're trying to do?
    – rpluim
    Commented Feb 22 at 11:14
  • I added some more details, does that help? The example from the Widget manual also inserts a newline: gnu.org/software/emacs/manual/html_mono/….
    – martian
    Commented Feb 22 at 12:43

1 Answer 1

1

turns out it's possible, and the trick is only that you need wrangle the :format argument not of the menu-choice widget, but its item or choice-item children, as that is there the newline is snuck in to the machinery.

example :format "%[%v%] "

Source: emacs bug email list widget expert Bug#69457.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.