I'm currently trying to improve the advanced-return function for C/C++, I found somewhere on the internet. It basically detects if a comment is started and on hitting ENTER continues it on the next line. I was able to improve the single line comment detection, but failed trying to implement behaviour I witnessed the c-electric-paren function (and others) doing. By hitting C-q prior to the respective paren key, it inserts a literal paren, skipping the balancing. This functionality I want to replicate, i.e. C-q <RET> should only insert a newline and not try to continue a potential comment.
By looking at the source of c-electric-paren, I reckoned it must have something to do with the interactive specification and managed to cook up a basic example:
(defun cq-test (arg) (interactive "*P") (if (not arg) (message-box "No argument provided.") (if (> (prefix-numeric-value arg) 0) (message-box "Called with numeric argument.") (message-box "C-q but no numeric value provided") ) ) I then bound this test function to <RET> for quick testing. The (not arg) part works and detects C-q not being hit prior to invocation. But as soon as I hit C-q right before, my function does not seem to be invoked at all (none of the message boxes appearing whatsoever), but a strange character (^M in my case) is being added to the buffer (a control character representing the line ending maybe?).
I feel like I'm somewhat close to a solution, but missing some crucial fact(s). Can someone explain to me why my function is not invoked at all with C-q? Could someone also please tell me if my handling of arg is able to achieve the behaviour I'm looking for?
M-jprovide theadvanced-returnbehaviour you were originally wanting?advanced-returnI have.