/* * Contents: * * command scroll-other-window on C-A-V * scrolls other window link C-V * * command insert-comment on A-; * inserts a new or moves to existing comment specific to mode. * This file only considers C mode. The (buffer specific) variables * which control the behavior of this command are: * comment_col: Column where comment begins * default_comment_col: Default for above * comment_begin: String which specifies beginning of comment * comment_pat: R-E string used to locate comments * * c-mode-hook: * Sets up the variables above when C-mode is entered. * * command set-comment-column on C-X ; * Sets the current or default comment column * * command add-edit-history on A-* * Moves to end of buffer, inserts comment with time, date and name * and leaves cursor positioned in comment for entering description. * * command insert-date * command insert-time-and-date * Obvious. * * command rm * Prompts for and deletes a file. * */ #include "eel.h" /* * Scroll Other Window */ command scroll_other_window() on reg_tab[CTRL(ALT('v'))] { window_number++; if (has_arg) previous_page (); else next_page (); window_number--; } /* * C Mode */ #define C_COMMENT_PAT "^.*/%*.!" #define C_COMMENT_END "*/" #define C_COMMENT_BEGIN "/* " int default_comment_col = 40; buffer int comment_col = 40; buffer char *comment_begin; buffer char *comment_end; buffer char *comment_pat; command insert_comment() on reg_tab[ALT(';')] { int n, p; iter = 0; if (!comment_pat) { comment_pat = "^.*;.!"; comment_begin = "; "; comment_end = ""; } to_begin_line(); n = point; to_end_line(); p = point; point = n; if (re_search(1, comment_pat)) { if (point < p) { return; } } point = n; to_end_line(); delete_horizontal_space(); p = point; if ((p - n) < comment_col) to_column(comment_col); else insert ('\t'); bprintf ("%s", comment_begin); p = point; bprintf ("%s", comment_end); point = p; } command set_comment_column() on cx_tab[';'] { iter = 0; if (has_arg) { comment_col = default_comment_col; } else { comment_col = current_column (); } say ("Comment column set to %d in this buffer", comment_col); } c_mode_hook () { comment_pat = C_COMMENT_PAT; comment_end = C_COMMENT_END; comment_begin = C_COMMENT_BEGIN; } char *edit_history_name = 0; command add_to_edit_history() on reg_tab[ALT('*')] { int opoint; char user[30]; struct time_info tinfo; char *name = has_arg ? 0 : edit_history_name; if (!name) { if (!has_arg) name = getenv ("USER"); if (!name) { get_cmd (user, "Your name: "); name = user; } edit_history_name = strsave (name); } iter = 0; goto_end(); re_search(-1, "[^\n\r\t ]"); point++; insert ('\n'); delete (point, size()); if (comment_begin) bprintf("%s", comment_begin); time_and_day (&tinfo); bprintf("%d/%d/%d %d:%d -- %s -- ", tinfo.month, tinfo.day, tinfo.year - 1900, tinfo.hour, tinfo.minute, name); if (comment_end) { opoint = point; bprintf("%s", comment_end); point = opoint; } } command insert_date() { struct time_info tinfo; time_and_day (&tinfo); bprintf("%d/%d/%d", tinfo.month, tinfo.day, tinfo.year - 1900); } command insert_time_and_date() { struct time_info tinfo; time_and_day (&tinfo); bprintf("%d/%d/%d %d:%d", tinfo.month, tinfo.day, tinfo.year - 1900, tinfo.hour, tinfo.minute); } command rm() { char fname[FNAMELEN]; iter = 0; get_file_dir(fname, "Delete file: ", filename); if (delete_file(fname)) sayput("File NOT deleted"); else sayput("File deleted"); }