home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- ******************************************************* LineComment Routine **
- *****************************************************************************/
-
- export void LineComment()
- {
- int width = ReadInfo("wall_right");
- string comment = PromptString("","Enter comment","");
- int col;
- string output;
- string startstop = "*"; /* Default chars are for */
- string body = "*"; /* assembler mode */
-
- if ((strlen(comment)!=0) && (strlen(comment) < (width - 3 - 3)))
- {
- if (width==0) /* Fallback if no right_wall */
- {
- width = 79;
- }
-
- if (ReadInfo("c_mode")) /* C style comment chars */
- {
- startstop = "/";
- body = "*";
- }
-
- if (ReadInfo("line_length")!=1) /* Only use newline if not invoked */
- { /* on an empty line */
- End();
- output = "\n";
- }
-
- output = joinstr(output, startstop);
- for (col = 2; col < width; col++)
- {
- output = joinstr(output, body);
- }
- output = joinstr(output, "\n");
-
- for (col = 1; col < (width -2-1-1 - strlen(comment)); col++)
- {
- output = joinstr(output, body);
- }
-
- output = joinstr(output, " ", comment, " ", body, body, "\n");
-
- for (col = 1; col < width-1; col++)
- {
- output = joinstr(output, body);
- }
- Output(joinstr(output, startstop,"\n"));
- }
-
- }
-
-
- /*****************************************************************************
- ******************************************************** EOLComment Routine **
- *****************************************************************************/
-
- export void EOLComment()
- {
- int cur_col;
- int dest_col = ReadInfo("comment_column");
- string output = "";
- int tabsize = ReadInfo("tab_size");
- int cursor_left=0;
- int dest_tabs,dest_spc,needed_tabs;
-
- End();
- cur_col = ReadInfo("column");
- if (cur_col < dest_col) /* Insert some tabs'n'spaces to */
- { /* reach comment column if needed */
- dest_tabs = dest_col/tabsize;
- dest_spc = dest_col - tabsize*dest_tabs -1;
-
- needed_tabs = (dest_tabs*tabsize - cur_col)/tabsize +1;
-
- if (dest_spc>0 && dest_tabs==(cur_col/tabsize)) /* don't ask! :) */
- {
- needed_tabs--;
- }
-
- if (needed_tabs <= 0) /* Only space insertion */
- {
- needed_tabs = 0;
- dest_spc = dest_col - cur_col; /* Recalc amount of spaces */
- }
-
-
- for (;needed_tabs > 0;needed_tabs--) /* Insert tabs */
- {
- output = joinstr(output, "\t");
- }
-
- for (;dest_spc > 0;dest_spc--) /* Insert spaces */
- {
- output = joinstr(output, " ");
- }
- }
- /* Determine comment type */
- if (ReadInfo("c_mode")) /* C style */
- {
- output = joinstr(output, " /* */");
- cursor_left = 3;
- }
-
- if (ReadInfo("asm_mode")) /* Assembler style */
- {
- output = joinstr(output, " ;");
- }
-
- Output(output); /* Do the output */
- CursorLeft(cursor_left); /* and reposition cursor */
- }
-
- /*****************************************************************************
- ****************************************************** Default key bindings **
- *****************************************************************************/
-
- AssignKey("LineComment();", "'esc' :");
- AssignKey("EOLComment();", "'esc' ;");
-
-
- /*****************************************************************************
- ********************************************************** Public variables **
- *****************************************************************************/
-
- ConstructInfo("comment_column","","","LIW","",1,999,41);
- ConstructInfo("wall_right", "", "", "WIL", "", 0, 999, 79);
-