diff options
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 7 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 10 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 7 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 7 | ||||
-rw-r--r-- | doc/sr/weechat_plugin_api.sr.adoc | 8 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 113 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 2 |
8 files changed, 126 insertions, 29 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 5aa5d5246..e0647e0b0 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -27,6 +27,7 @@ New features:: * core: force ctrl keys to lower case when they are added (issue #1875) * core: add command `/reset` to reset options to their default values * core: add option `rename` in command `/bar` + * core: add relative move of read marker with `/buffer set unread [+/-]N` (issue #1895) * core: add access to hashtable properties in evaluation of expressions (issue #1888) * core: display similar command names when a command is unknown (issue #1877) * core, plugins: make many identifiers case sensitive (issue #1872, issue #398, bug #32213) diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 34fcab84e..ba50be736 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -13977,9 +13977,12 @@ Properties: "1": do not stop completion when command line is updated (global setting, buffer pointer is not used). -| unread | | empty string or "0" +| unread | | empty string, "0", "+N", "-N" or "N" (N is integer) | empty string: set unread marker after last line of buffer + - "0": remove unread marker from buffer. + "0": remove unread marker from buffer + + "N": move the unread marker N lines from the end towards the first line of buffer + + "-N": move the unread marker N lines towards the first line of buffer + + "+N": move the unread marker N lines towards the last line of buffer. | display | | "1" or "auto" | "1": switch to this buffer in current window + diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index e55ad3907..b9f3e8de6 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -14283,10 +14283,12 @@ Propriétés : "1" : ne pas arrêter la complétion lorsque la ligne de commande est mise à jour (option globale, le pointeur vers le tampon n'est pas utilisé). -| unread | | chaîne vide ou "0" -| chaîne vide : définit le marqueur de données non lues après la dernière ligne - du tampon + - "0" : supprime le marqueur de données non lues du tampon. +| unread | | chaîne vide, "0", "+N", "-N" ou "N" (N est un entier) +| chaîne vide : définir le marqueur de données non lues après la dernière ligne du tampon + + "0" : supprimer le marqueur de données non lues du tampon + + "N" : déplacer le marqueur de données non lues de N lignes depuis la fin vers la première ligne du tampon + + "-N" : déplacer le marqueur de données non lues de N lignes vers la première ligne du tampon + + "+N" : déplacer le marqueur de données non lues de N lignes vers la dernière ligne du tampon. | display | | "1" ou "auto" | "1" : basculer vers ce tampon dans la fenêtre active + diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index ae6ccd21f..acd9ca03f 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -14620,9 +14620,12 @@ Properties: (impostazione globale, il puntatore al buffer non è utilizzato). // TRANSLATION MISSING -| unread | | empty string or "0" +| unread | | empty string, "0", "+N", "-N" or "N" (N is integer) | empty string: set unread marker after last line of buffer + - "0": remove unread marker from buffer. + "0": remove unread marker from buffer + + "N": move the unread marker N lines from the end towards the first line of buffer + + "-N": move the unread marker N lines towards the first line of buffer + + "+N": move the unread marker N lines towards the last line of buffer. | display | | "1" oppure "auto" | "1": passa a questo buffer nella finestra corrente + diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 0fc72618a..558a4a8f4 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -14132,9 +14132,12 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, (グローバル設定、バッファへのポインタは使われない) // TRANSLATION MISSING -| unread | | empty string or "0" +| unread | | empty string, "0", "+N", "-N" or "N" (N is integer) | empty string: set unread marker after last line of buffer + - "0": remove unread marker from buffer. + "0": remove unread marker from buffer + + "N": move the unread marker N lines from the end towards the first line of buffer + + "-N": move the unread marker N lines towards the first line of buffer + + "+N": move the unread marker N lines towards the last line of buffer. | display | | "1" または "auto" | "1": 指定したバッファを現在のウィンドウに表示 + diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index fadafeea6..f5cd2c95b 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -13496,9 +13496,13 @@ void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property, "1": довршавање се не зауставља када се ажурира командна линија (глобално подешавање, не користи се показивач на бафер). -| unread | | празан стринг или "0" +// TRANSLATION MISSING +| unread | | empty string, "0", "+N", "-N" or "N" (N is integer) | празан стринг: поставља ознаку непрочитано након последње линије бафера + - "0": уклања ознаку непрочитано из бафера. + "0": уклања ознаку непрочитано из бафера + + "N": move the unread marker N lines from the end towards the first line of buffer + + "-N": move the unread marker N lines towards the first line of buffer + + "+N": move the unread marker N lines towards the last line of buffer. | display | | "1" или "auto" | "1": прелазак на овај бафер у текућем прозору + diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index ab75c2cce..c2dbae298 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -2108,36 +2108,120 @@ gui_buffer_set_input_multiline (struct t_gui_buffer *buffer, /* * Sets unread marker for a buffer. * - * If remove_marker == 1, then unread marker is removed, otherwise it's set - * after the last line. + * Argument is a string that can be: + * - empty string or NULL: set unread marker after the last line + * - "0": remove unread marker from buffer + * - "-N" or "+N" (N = integer): move the read marker + * (negative number: to older line, positive number: to newer line) + * - "N" (N = integer but not 0): mark N latest messages as unread */ void -gui_buffer_set_unread (struct t_gui_buffer *buffer, int remove_marker) +gui_buffer_set_unread (struct t_gui_buffer *buffer, const char *argument) { - int refresh; + struct t_gui_line *old_last_read_line; + int i, old_first_line_not_read; + long number; + char *error; if (!buffer || (buffer->type != GUI_BUFFER_TYPE_FORMATTED)) return; - if (remove_marker) + old_last_read_line = buffer->lines->last_read_line; + old_first_line_not_read = buffer->lines->first_line_not_read; + + if (!argument || !argument[0]) + { + /* set unread marker after last line */ + buffer->lines->last_read_line = buffer->lines->last_line; + buffer->lines->first_line_not_read = (buffer->lines->last_read_line) ? 0 : 1; + } + else if (strcmp (argument, "0") == 0) { /* remove unread marker */ - refresh = (buffer->lines->last_read_line != NULL); buffer->lines->last_read_line = NULL; buffer->lines->first_line_not_read = 0; } + else if (argument[0] == '-') + { + /* move the unread marker N lines towards the first line */ + number = strtol (argument, &error, 10); + if (error && !error[0] && (number < 0)) + { + for (i = 0; i > number; i--) + { + if (!buffer->lines->last_read_line) + { + if (!buffer->lines->last_line + || buffer->lines->first_line_not_read) + { + break; + } + buffer->lines->last_read_line = buffer->lines->last_line; + } + if (!buffer->lines->last_read_line->prev_line) + { + buffer->lines->last_read_line = NULL; + buffer->lines->first_line_not_read = 1; + break; + } + buffer->lines->last_read_line = buffer->lines->last_read_line->prev_line; + } + } + } + else if (argument[0] == '+') + { + /* move the unread marker N lines towards the last line */ + number = strtol (argument, &error, 10); + if (error && !error[0] && (number > 0)) + { + for (i = 0; i < number; i++) + { + if (!buffer->lines->last_read_line) + { + if (!buffer->lines->first_line + || !buffer->lines->first_line_not_read) + { + break; + } + buffer->lines->last_read_line = buffer->lines->first_line; + buffer->lines->first_line_not_read = 0; + continue; + } + buffer->lines->last_read_line = buffer->lines->last_read_line->next_line; + if (!buffer->lines->last_read_line) + break; + } + } + } else { - /* set unread marker after last line */ - refresh = ((buffer->lines->last_read_line != NULL) - && (buffer->lines->last_read_line != buffer->lines->last_line)); - buffer->lines->last_read_line = buffer->lines->last_line; - buffer->lines->first_line_not_read = (buffer->lines->last_read_line) ? 0 : 1; + /* move the unread marker N lines from the end towards the first line */ + number = strtol (argument, &error, 10); + if (error && !error[0] && (number > 0)) + { + buffer->lines->last_read_line = buffer->lines->last_line; + buffer->lines->first_line_not_read = 0; + for (i = 0; i < number; i++) + { + if (!buffer->lines->last_read_line) + break; + if (!buffer->lines->last_read_line->prev_line) + { + buffer->lines->last_read_line = NULL; + buffer->lines->first_line_not_read = 1; + break; + } + buffer->lines->last_read_line = buffer->lines->last_read_line->prev_line; + } + } } - if (refresh) + if ((old_last_read_line != buffer->lines->last_read_line + || old_first_line_not_read != buffer->lines->first_line_not_read)) + { gui_buffer_ask_chat_refresh (buffer, 2); + } } /* @@ -2148,7 +2232,7 @@ void gui_buffer_set (struct t_gui_buffer *buffer, const char *property, const char *value) { - int gui_chat_mute_old, remove_marker; + int gui_chat_mute_old; long number; char *error; const char *ptr_notify; @@ -2195,8 +2279,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, /* properties that need a buffer */ if (strcmp (property, "unread") == 0) { - remove_marker = (strcmp (value, "0") == 0); - gui_buffer_set_unread (buffer, remove_marker); + gui_buffer_set_unread (buffer, value); } else if (strcmp (property, "display") == 0) { diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 924687e5b..abf381276 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -330,8 +330,6 @@ extern void gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer, const char *new_tags); extern void gui_buffer_set_hotlist_max_level_nicks (struct t_gui_buffer *buffer, const char *new_hotlist_max_level_nicks); -extern void gui_buffer_set_unread (struct t_gui_buffer *buffer, - int remove_marker); extern void gui_buffer_set (struct t_gui_buffer *buffer, const char *property, const char *value); extern void gui_buffer_set_pointer (struct t_gui_buffer *buffer, |