0

I need to extract certain information from buffer names, and I'm doing so by extracting substrings based on the position of unique characters within a buffer name string.

So, I currently am doing something like this:

(substring (buffer-name) (1+ (search "%" (buffer-name))) (search "&" (buffer-name)))

But when I do flycheck it complains: "function 'search' from cl pacakge called at runtime".

Is there a good method of search for the first occurrence of a character within a string that I can use that doesn't require calling (require 'cl-lib) [or (eval-when-compile (require 'cl-lib)), which produces the same complaint]? Or would I have to write the string out to a temporary buffer?

  • Why don’t you want to use cl-lib, out of curiosity? – Dan Jan 9 at 0:45
  • @Dan I'd like ultimately to submit as a MELPA package, and flycheck is flagging the use as per above. (Also, I'm curious about what good non-cl ways would be.) – emacsomancer Jan 9 at 2:37
  • 2
    search is in cl.el, not cl-lib.el. Does it complain if you use cl-search ? – phils Jan 9 at 3:25
  • @phils ah! you're right, it doesn't complain for cl-search. – emacsomancer Jan 9 at 5:54
2

It looks like you ultimately want the characters between % and & in the buffer name?

You might do this:

(let ((s (buffer-name)))
  (string-match "%\\(.*?\\)&" s)
  (match-string 1 s))

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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