Could I write the if condition on the same line. Is there any other way to include the equivalent of the if conditional in a more compact way ?

 (pcase grapheme
       (if (equal var "this")
           (insert "this")
         (insert "that"))))
  • 3
    Welcome! Have you tried it to see what happens?
    – Dan
    Aug 15 at 9:38
  • 1
    (insert (if (equal var "this") "this" "that")) or (insert (or (and (equal var "this") "this") "that")) Sometimes one uses the and-or-construct when the expression returns something.
    – Tobias
    Aug 15 at 9:51
  • 1
    Based on the last question, I'm guessing you're using a pcase statement with dozens of possible choices to insert either a latex character or a greek UTF-8 character. If I'm right about this, then this is the wrong question to ask. Help us by telling us the real problem you're trying to solve.
    – Trevoke
    Aug 15 at 11:57
  • @Trevoke: "If I'm right about this, then this is the wrong question to ask." -- IMHO, we could answer the question even if it's wrong. Following this principle, we don't need to worry about whether the question is wrong or not -- If it's not wrong, that's good; if it's wrong, we can still answer it, and OP (and perhaps other readers) can still learn something, which is also good.
    – shynur
    Aug 15 at 15:11

2 Answers 2


Yes. Just make these things functions and call the functions. That's how all programming works. You put multiple lines of code in one line of code by wrapping the multiple lines of code into a function.


Only to show that this could be a XY-problem (TLDR: If we knew better what you want to do we could give you better help.):

If you are testing var in each of the pcase cases you could include that variable in the pcase-conditions:

(pcase (list grapheme var)
    ('("dinkus" "this")  
     "this value")  
    (`("dinkus" ,_)  
     "that value"))

Disclaimer: I actually wanted to write this text as a comment. But, that comment turned out to be unreadable because of the missing newlines in the code. So I ended up writing an answer. But, maybe it is even acceptable as one of the possible answers.


Your Answer

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