I have this elisp code from yasnippet:
`(progn (goto-char (point-min)) (unless (re-search-forward
"^using\\s-+namespace std;" nil 'no-errer) "std::"))
`cout << $0${1:} << "${2:\n}";
which will print:
cout << ... << "\n";
when you type cout
and TAB
to complete. Note that ...
is where my cursor will be.
If I don't have using namespace std
in my C++
code, then the insertion becomes:
std:: cout << ... << "\n";
Instead of the newline character, \n
, I tried to modify so that endl
is printed instead. In other words:
cout << ... << endl;
and
std::cout << ... << std::endl;
Question
How to have std::
inserts at both cout
and endl
if no using namespace std;
is found?
Attempts
I tried the followings, none of them work:
`(progn (goto-char (point-min)) (unless (re-search-forward
"^using\\s-+namespace std;" nil 'no-errer) "std::"))
`cout << $0${1:} << endl;
This only prints std::
to the front, cout
if I do not have the using namespace std;
.
`(progn (goto-char (point-min)) (unless (re-search-forward
"^using\\s-+namespace std;" nil 'no-errer) "std::"))
`cout << $0${1:}
`(progn (goto-char (point-min)) (unless (re-search-forward
"^using\\s-+namespace std;" nil 'no-errer) "std::"))
'endl;
This previous code just prints out:
cout << ...
`(progn (goto-char (point-min)) (unless (re-search-forward
"^using\\s-+namespace std;" nil 'no-errer) "std::"))
'endl;