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?

4
  • Why don’t you want to use cl-lib, out of curiosity? Commented Jan 9, 2019 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.) Commented Jan 9, 2019 at 2:37
  • 2
    search is in cl.el, not cl-lib.el. Does it complain if you use cl-search ? Commented Jan 9, 2019 at 3:25
  • @phils ah! you're right, it doesn't complain for cl-search. Commented Jan 9, 2019 at 5:54

1 Answer 1

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)) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.