I have this function that sets the isearch-filter-predicate variable to a predicate (function) from a list of predicates:

(defun set-isearch-filter-predicate ()

  (unless (boundp 'IFP-default)
    (setq IFP-default isearch-filter-predicate))

  (let* ((INIT (symbol-name IFP-default))
     (IFP_STRING (read-string "Choose predicate: " INIT nil PREDICATES))
     (IFP (intern-soft IFP_STRING)))

    (setq isearch-filter-predicate IFP)))

I'd like to view the "name" (e.g. "predicate1") of the predicate I've setted in the mode-line. Is it possible without define specific minor-modes?

I'd like also to know how to use symbols instead of strings (e.g. predicate1 instead of "predicate1" in my code, but it's not vital (I tried read-command instead of read-string but it doesn't work).

  • Please ask only one question per question. Please move your question about the 4th arg to read-string to another question. Thx.
    – Drew
    Mar 8 '19 at 19:53
  • Anyway, wrt your question about using symbols as candidates for a read function: use completing-read. You cannot use a list of symbols as the DEFAULT-VALUE argument (to read-string, read-command, completing-read, or other functions), but you can use it as the COLLECTION arg to completing-read.
    – Drew
    Mar 8 '19 at 20:19
  • You can of course apply symbol-name to each predicate symbol, and use the result as a DEFAULT-VALUE arg in read-string or whatever - e.g. mapcar symbol-name over your list of predicate symbols. But completing-read is what you want to use, in general - allow the user completion.
    – Drew
    Mar 8 '19 at 20:33
  • @Drew, thank you for the hints. Do you still suggest to move the second question in a separate one? Mar 8 '19 at 23:28
  • That's for you to decide. If you think it would help other users, why not?
    – Drew
    Mar 8 '19 at 23:49
  1. Why do you not want to define a minor mode here? It's as simple as this - in this case I put a character into the mode line, in global-mode-string, but you can adapt the code.
    (defvar mlc-char-in-mode-line-mode-initialized nil
      "Non-nil if `mlc-char-in-mode-line-mode' has been called.")

    (define-minor-mode mlc-char-in-mode-line-mode
      "Show char after point in mode line, at start of `global-mode-string'."
      nil nil nil :group 'Modeline
      (unless mlc-char-in-mode-line-mode-initialized
        (setq mlc-char-in-mode-line-mode-initialized  t)
        (setq global-mode-string
              (cond ((consp global-mode-string)
                     (add-to-list 'global-mode-string mlc-mode-line-char-format))
                    ((not global-mode-string)
                     (list mlc-mode-line-char-format))
                    ((stringp global-mode-string)
                     (list mlc-mode-line-char-format global-mode-string))))))

mlc-mode-line-char-format does essentially this:

    (let* ((ch   (following-char))
           (str  (format (if (= ?% ch) "[%%%c=%06x] " "[%c=%06x] ") ch ch)))
  1. More generally, you can use one of the mode-line variables described in the Elisp manual, node Mode Line Variables. See node Mode Line Data for an understanding of how data you put in the mode line needs to be formatted.

    In particular, you can show the value of a symbol in the mode line just by inserting the symbol there. From Mode Line Data:

A symbol as a mode line construct stands for its value. The value of SYMBOL is used as a mode line construct, in place of SYMBOL. However, the symbols t and nil are ignored, as is any symbol whose value is void.

There is one exception: if the value of SYMBOL is a string, it is displayed verbatim: the %-constructs are not recognized.

Unless SYMBOL is marked as risky (i.e., it has a non-nil risky-local-variable property), all text properties specified in SYMBOL’s value are ignored. This includes the text properties of strings in SYMBOL’s value, as well as all :eval and :propertize forms in it. (The reason for this is security: non-risky variables could be set automatically from file variables without prompting the user.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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