first of all thanks for this editor... it's the FIRST thing I install whenever I put my pawns on a machine!
I had a question: is there a way to automagically comment (i.e. add a "#" at the beginning of a line) a selected block of text?
It's be useful when I edit files like /etc/network/interfaces or xorg.conf.
Thanks for your help and keep up the good work!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As far as I know, there is no comment/uncomment command. Two ways you could do it are:
^[B
^KF
\^\*\$
rk
#\&
r
or
^K/
sed 's/^.*$/#&/'
The second method might be faster if you do the same operation many times in a file since you can hit up to recall the sed command after entering it the first time. Unfortunately the history for filter commands does not persist between invocations of joe. The history for search and replace commands does, so that might be faster if you open and close joe frequently.
Charles J. Tabony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This certainly could be, and probably should be, made a command. For some types of files, JOE knows the syntax of comments and uses that knowledge to ignore the contents of comments when searching for matching delimiters. However, the different styles of comments are hard coded. See this snippet of code from uedit.c:
} else if ((bw->o.pound_comment && d == '#') ||
(bw->o.semi_comment && d == ';') ||
(bw->o.vhdl_comment && d == '-' && brch(p) == '-')) {
while ((d = pgetc(p)) != NO_MORE_DATA)
if (d == '\n')
break;
} else if ((bw->o.c_comment || bw->o.cpp_comment) && d == '/') {
It would be good if JOE had some more general way of handling comment styles, such as being able to specify the string that starts a comment and the string that terminates a comment (which in most cases is a newline).
For comments that end with a newline, a "comment block" operation would be simple. Other types of comments, like C style comments would be trickier. Every person has their own style of commenting a block of text. Also, what would you do if the block already contained a comment? If you want an uncomment block command, then how would it undo your solution to the last question?
If you (or someone reading this) want to implement this, then you can use urindent or ulindent in ublock.c as a starting point. Speaking of which, you can actually comment a block with pound signs by going to options (^T), selecting "Indent char", entering 35 (the ASCII code for '#'), and then using the indent block command. Just make sure you set the indent character back before you try to actually indent something.
You can make a semi-permanent shortcut for any sequence of commands using macros. Hit "^K[", enter a number from 0 through 9, then enter one of the sequences of commands above, then hit "^K]". Later, you can hit ^K followed by the number you entered to perform the sequence of commands. The macro will be remembered between sessions of JOE. If you use the first sequence and you don't want your cursor to move when you invoke the macro, then you can add two "^K-"s to the end of the sequence like so:
^K[
0
^[B
^KF
\^\*\$
rk
#\&
r
^K-
^K-
^K]
uncomment block macro:
^K[
1
^[B
^KF
\^#\*\$
rk
\0
r
^K-
^K-
^K]
Charles J. Tabony
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A little late reply, but I thought I'd share my solution. It might be useful for some of you.
I created two macros for commenting and uncommenting selected lines (Ctrl + arrow), and bound them to the keyboard combinations: ^K ^C and ^K ^U respectrively. I made it so that this works only for files with the extension "sh", thus the comment indicator: #. For other file types it will not be active.
Hello Arpad! JOE editor patron as well!
Thanks for the macro! I too was looking for a similar to emacs for commenting regions.
I'm trying to get your macro to work with a file-type other than .sh - so I modified your macro in my ~/.joerc file. Unfortunately, I cannot get it to work at all. However, it may be because I use jmacs. Any ideas? Thanks again!
Duke
Last edit: Duke Normandin 2022-05-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello joe developers,
first of all thanks for this editor... it's the FIRST thing I install whenever I put my pawns on a machine!
I had a question: is there a way to automagically comment (i.e. add a "#" at the beginning of a line) a selected block of text?
It's be useful when I edit files like /etc/network/interfaces or xorg.conf.
Thanks for your help and keep up the good work!
As far as I know, there is no comment/uncomment command. Two ways you could do it are:
^[B
^KF
\^\*\$
rk
#\&
r
or
^K/
sed 's/^.*$/#&/'
The second method might be faster if you do the same operation many times in a file since you can hit up to recall the sed command after entering it the first time. Unfortunately the history for filter commands does not persist between invocations of joe. The history for search and replace commands does, so that might be faster if you open and close joe frequently.
Charles J. Tabony
Any way of integrating this into Joe? Or making a semi-permanent shortcut defined for the operation?
This certainly could be, and probably should be, made a command. For some types of files, JOE knows the syntax of comments and uses that knowledge to ignore the contents of comments when searching for matching delimiters. However, the different styles of comments are hard coded. See this snippet of code from uedit.c:
} else if ((bw->o.pound_comment && d == '#') ||
(bw->o.semi_comment && d == ';') ||
(bw->o.vhdl_comment && d == '-' && brch(p) == '-')) {
while ((d = pgetc(p)) != NO_MORE_DATA)
if (d == '\n')
break;
} else if ((bw->o.c_comment || bw->o.cpp_comment) && d == '/') {
It would be good if JOE had some more general way of handling comment styles, such as being able to specify the string that starts a comment and the string that terminates a comment (which in most cases is a newline).
For comments that end with a newline, a "comment block" operation would be simple. Other types of comments, like C style comments would be trickier. Every person has their own style of commenting a block of text. Also, what would you do if the block already contained a comment? If you want an uncomment block command, then how would it undo your solution to the last question?
If you (or someone reading this) want to implement this, then you can use urindent or ulindent in ublock.c as a starting point. Speaking of which, you can actually comment a block with pound signs by going to options (^T), selecting "Indent char", entering 35 (the ASCII code for '#'), and then using the indent block command. Just make sure you set the indent character back before you try to actually indent something.
You can make a semi-permanent shortcut for any sequence of commands using macros. Hit "^K[", enter a number from 0 through 9, then enter one of the sequences of commands above, then hit "^K]". Later, you can hit ^K followed by the number you entered to perform the sequence of commands. The macro will be remembered between sessions of JOE. If you use the first sequence and you don't want your cursor to move when you invoke the macro, then you can add two "^K-"s to the end of the sequence like so:
^K[
0
^[B
^KF
\^\*\$
rk
#\&
r
^K-
^K-
^K]
uncomment block macro:
^K[
1
^[B
^KF
\^#\*\$
rk
\0
r
^K-
^K-
^K]
Charles J. Tabony
Hi!
A little late reply, but I thought I'd share my solution. It might be useful for some of you.
I created two macros for commenting and uncommenting selected lines (Ctrl + arrow), and bound them to the keyboard combinations: ^K ^C and ^K ^U respectrively. I made it so that this works only for files with the extension "sh", thus the comment indicator: #. For other file types it will not be active.
Just add this to your ~/.joerc
Cheers,
Arpad
Last edit: Arpad Jakab 2021-03-02
Hello Arpad! JOE editor patron as well!
Thanks for the macro! I too was looking for a similar to emacs for commenting regions.
I'm trying to get your macro to work with a file-type other than .sh - so I modified your macro in my ~/.joerc file. Unfortunately, I cannot get it to work at all. However, it may be because I use jmacs. Any ideas? Thanks again!
Duke
Last edit: Duke Normandin 2022-05-12
I have personally found for block commands using small shell scripts and sed/awk to a be a life saver and a simple way to extend Joe without macros.