commit 839743fd24e9c4aa67ad195f68970fd3cae19b0a
parent 0b30835dd0fc0e8bfcc665777aae2aa4802eab2b
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 1 Apr 2018 10:53:15 +0200
tweaks: move a function to its proper location
Diffstat:
M | src/proto.h | | | 1 | - |
M | src/text.c | | | 120 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
2 files changed, 60 insertions(+), 61 deletions(-)
diff --git a/src/proto.h b/src/proto.h
@@ -521,7 +521,6 @@ void do_unindent(void);
bool white_string(const char *s);
#ifdef ENABLE_COMMENT
void do_comment(void);
-bool comment_line(undo_type action, filestruct *f, const char *comment_seq);
#endif
void do_undo(void);
void do_redo(void);
diff --git a/src/text.c b/src/text.c
@@ -476,66 +476,6 @@ bool white_string(const char *s)
}
#ifdef ENABLE_COMMENT
-/* Comment or uncomment the current line or the marked lines. */
-void do_comment(void)
-{
- const char *comment_seq = GENERAL_COMMENT_CHARACTER;
- undo_type action = UNCOMMENT;
- filestruct *top, *bot, *line;
- bool empty, all_empty = TRUE;
-
-#ifdef ENABLE_COLOR
- if (openfile->syntax)
- comment_seq = openfile->syntax->comment;
-
- if (*comment_seq == '\0') {
- statusbar(_("Commenting is not supported for this file type"));
- return;
- }
-#endif
-
- /* Determine which lines to work on. */
- get_range((const filestruct **)&top, (const filestruct **)&bot);
-
- /* If only the magic line is selected, don't do anything. */
- if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) {
- statusbar(_("Cannot comment past end of file"));
- return;
- }
-
- /* Figure out whether to comment or uncomment the selected line or lines. */
- for (line = top; line != bot->next; line = line->next) {
- empty = white_string(line->data);
-
- /* If this line is not blank and not commented, we comment all. */
- if (!empty && !comment_line(PREFLIGHT, line, comment_seq)) {
- action = COMMENT;
- break;
- }
- all_empty = all_empty && empty;
- }
-
- /* If all selected lines are blank, we comment them. */
- action = all_empty ? COMMENT : action;
-
- add_undo(action);
-
- /* Store the comment sequence used for the operation, because it could
- * change when the file name changes; we need to know what it was. */
- openfile->current_undo->strdata = mallocstrcpy(NULL, comment_seq);
-
- /* Process the selected line or lines. */
- for (line = top; line != bot->next; line = line->next) {
- /* Comment/uncomment a line, and add undo data when line changed. */
- if (comment_line(action, line, comment_seq))
- update_multiline_undo(line->lineno, "");
- }
-
- set_modified();
- refresh_needed = TRUE;
- shift_held = TRUE;
-}
-
/* Test whether the given line can be uncommented, or add or remove a comment,
* depending on action. Return TRUE if the line is uncommentable, or when
* anything was added or removed; FALSE otherwise. */
@@ -598,6 +538,66 @@ bool comment_line(undo_type action, filestruct *line, const char *comment_seq)
return FALSE;
}
+/* Comment or uncomment the current line or the marked lines. */
+void do_comment(void)
+{
+ const char *comment_seq = GENERAL_COMMENT_CHARACTER;
+ undo_type action = UNCOMMENT;
+ filestruct *top, *bot, *line;
+ bool empty, all_empty = TRUE;
+
+#ifdef ENABLE_COLOR
+ if (openfile->syntax)
+ comment_seq = openfile->syntax->comment;
+
+ if (*comment_seq == '\0') {
+ statusbar(_("Commenting is not supported for this file type"));
+ return;
+ }
+#endif
+
+ /* Determine which lines to work on. */
+ get_range((const filestruct **)&top, (const filestruct **)&bot);
+
+ /* If only the magic line is selected, don't do anything. */
+ if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) {
+ statusbar(_("Cannot comment past end of file"));
+ return;
+ }
+
+ /* Figure out whether to comment or uncomment the selected line or lines. */
+ for (line = top; line != bot->next; line = line->next) {
+ empty = white_string(line->data);
+
+ /* If this line is not blank and not commented, we comment all. */
+ if (!empty && !comment_line(PREFLIGHT, line, comment_seq)) {
+ action = COMMENT;
+ break;
+ }
+ all_empty = all_empty && empty;
+ }
+
+ /* If all selected lines are blank, we comment them. */
+ action = all_empty ? COMMENT : action;
+
+ add_undo(action);
+
+ /* Store the comment sequence used for the operation, because it could
+ * change when the file name changes; we need to know what it was. */
+ openfile->current_undo->strdata = mallocstrcpy(NULL, comment_seq);
+
+ /* Process the selected line or lines. */
+ for (line = top; line != bot->next; line = line->next) {
+ /* Comment/uncomment a line, and add undo data when line changed. */
+ if (comment_line(action, line, comment_seq))
+ update_multiline_undo(line->lineno, "");
+ }
+
+ set_modified();
+ refresh_needed = TRUE;
+ shift_held = TRUE;
+}
+
/* Perform an undo or redo for a comment or uncomment action. */
void handle_comment_action(undo *u, bool undoing, bool add_comment)
{