Would like to have a function that selects a string (from a list or from a user-defined string, using the mini-buffer) and a selected region.

User would input (), [], {} specifying the opening and closing bracket mark. The function would then extract the first and second character for use as the opening bracket and closing bracket respectively.

1 Answer 1


You apparently want a command that prompts for one of a set of 2-char strings. The command should return those two chars (e.g. in a list), and it should echo them in a message.

You also want the command to accept as argument the region limits. But the command doesn't do anything with them - you left that out of your question. Anyway, this shows how to do what you asked.

(defcustom delimiter-strings '("()" "[]" "{}")
  "Two-character strings of open and close delimiters."
  :type '(repeat string)
  :group 'convenience)

(defun echo-delimiter-chars (string start end)
  "Enter a 2-char string of delimiters, see what they are, return them."
  (interactive (list (completing-read "Delimiter pair: " delimiter-strings nil t)
  (let ((open   (aref string 0))
        (close  (aref string 1)))
    (message "Delimiters you've chosen: `%c' and `%c'" open close)
    (list open close)))
  • This would only allow (), [], {}. Want also to allow users to pass their own such as (] for situations where the opening and closing options do not match the list in delimiter-strings.
    – Dilna
    Mar 19, 2022 at 18:09
  • As usual (so far), what you think you're asking, or what you want to ask, is not what you asked. Post a different question if you like, to get (closer) to what you actually intended.
    – Drew
    Mar 19, 2022 at 19:08
  • Have changed the question.
    – Dilna
    Mar 19, 2022 at 22:38
  • Please do NOT change the question. (I've rolled back your edit.) You asked a question, and it was answered. Don't change it to a different question. Just post a new question. If you then don't want to keep the original question then delete it. Keep changing questions and you'll likely find that people are less willing to try to help you. Think about just what you want to ask before asking it. Try to state your question clearly. This will help you, as well as those trying to help you.
    – Drew
    Mar 19, 2022 at 23:36

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.