2014-01-07 18:26:07 +00:00
|
|
|
/*
|
|
|
|
|
* Org mode for QEmacs.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2001-2002 Fabrice Bellard.
|
2024-07-27 23:15:54 +02:00
|
|
|
* Copyright (c) 2002-2024 Charlie Gordon.
|
2014-01-07 18:26:07 +00:00
|
|
|
* Copyright (c) 2014 Francois Revol.
|
|
|
|
|
*
|
2023-03-05 02:04:02 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2014-01-07 18:26:07 +00:00
|
|
|
*
|
2023-03-05 02:04:02 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2014-01-07 18:26:07 +00:00
|
|
|
*
|
2023-03-05 02:04:02 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2014-01-07 18:26:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "qe.h"
|
|
|
|
|
|
2014-04-02 12:58:12 +00:00
|
|
|
enum {
|
|
|
|
|
IN_ORG_BLOCK = 0x80,
|
|
|
|
|
IN_ORG_LISP = 0x40,
|
|
|
|
|
IN_ORG_TABLE = 0x20,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
ORG_STYLE_TODO = QE_STYLE_STRING,
|
|
|
|
|
ORG_STYLE_DONE = QE_STYLE_TYPE,
|
|
|
|
|
ORG_STYLE_BULLET1 = QE_STYLE_FUNCTION,
|
|
|
|
|
ORG_STYLE_BULLET2 = QE_STYLE_STRING,
|
|
|
|
|
ORG_STYLE_BULLET3 = QE_STYLE_VARIABLE,
|
|
|
|
|
ORG_STYLE_BULLET4 = QE_STYLE_TYPE,
|
|
|
|
|
ORG_STYLE_COMMENT = QE_STYLE_COMMENT,
|
|
|
|
|
ORG_STYLE_PREPROCESS = QE_STYLE_PREPROCESS,
|
|
|
|
|
ORG_STYLE_CODE = QE_STYLE_FUNCTION,
|
|
|
|
|
ORG_STYLE_PROPERTY = QE_STYLE_KEYWORD,
|
|
|
|
|
ORG_STYLE_TABLE = QE_STYLE_TYPE,
|
|
|
|
|
ORG_STYLE_EMPHASIS = QE_STYLE_STRING,
|
|
|
|
|
};
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
#define MAX_LEVEL 128
|
2014-01-07 18:26:07 +00:00
|
|
|
|
|
|
|
|
/* TODO: define specific styles */
|
|
|
|
|
static struct OrgTodoKeywords {
|
|
|
|
|
const char *keyword;
|
|
|
|
|
int style;
|
|
|
|
|
} OrgTodoKeywords [] = {
|
2014-04-02 12:58:12 +00:00
|
|
|
{ "TODO", ORG_STYLE_TODO },
|
|
|
|
|
{ "DONE", ORG_STYLE_DONE },
|
2014-01-07 18:26:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* TODO: define specific styles */
|
|
|
|
|
#define BULLET_STYLES 5
|
|
|
|
|
static int OrgBulletStyles[BULLET_STYLES] = {
|
2014-04-02 12:58:12 +00:00
|
|
|
ORG_STYLE_BULLET1,
|
|
|
|
|
ORG_STYLE_BULLET2,
|
|
|
|
|
ORG_STYLE_BULLET3,
|
|
|
|
|
ORG_STYLE_BULLET4,
|
2014-01-07 18:26:07 +00:00
|
|
|
};
|
|
|
|
|
|
2022-10-29 19:43:38 +02:00
|
|
|
static int org_todo_keyword(const char32_t *str)
|
2014-01-07 18:26:07 +00:00
|
|
|
{
|
2015-06-19 14:23:55 +00:00
|
|
|
int kw, len;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-11 15:38:28 +00:00
|
|
|
for (kw = 0; kw < countof(OrgTodoKeywords); kw++) {
|
2015-06-19 14:23:55 +00:00
|
|
|
if (ustrstart(str, OrgTodoKeywords[kw].keyword, &len) && str[len] == ' ')
|
2014-01-11 15:38:28 +00:00
|
|
|
return kw;
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-29 19:43:38 +02:00
|
|
|
static int org_scan_chunk(const char32_t *str,
|
2014-01-10 01:25:14 +00:00
|
|
|
const char *begin, const char *end, int min_width)
|
|
|
|
|
{
|
2014-01-20 18:04:00 +00:00
|
|
|
int i, j;
|
2014-01-10 01:25:14 +00:00
|
|
|
|
2014-01-20 18:04:00 +00:00
|
|
|
for (i = 0; begin[i]; i++) {
|
2022-08-22 17:13:26 +02:00
|
|
|
if (str[i] != (u8)begin[i])
|
2014-01-10 01:25:14 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2014-01-20 18:04:00 +00:00
|
|
|
for (j = 0; j < min_width; j++) {
|
|
|
|
|
if (str[i + j] == '\0')
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
for (i += j; str[i] != '\0'; i++) {
|
2014-01-10 01:25:14 +00:00
|
|
|
for (j = 0; end[j]; j++) {
|
2022-08-22 17:13:26 +02:00
|
|
|
if (str[i + j] != (u8)end[j])
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!end[j])
|
2014-01-20 18:04:00 +00:00
|
|
|
return i + j;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-05 15:49:14 +00:00
|
|
|
static void org_colorize_line(QEColorizeContext *cp,
|
2024-07-27 23:15:54 +02:00
|
|
|
const char32_t *str, int n,
|
|
|
|
|
QETermStyle *sbuf, ModeDef *syn)
|
2014-01-07 18:26:07 +00:00
|
|
|
{
|
2014-04-05 15:49:14 +00:00
|
|
|
int colstate = cp->colorize_state;
|
2014-01-11 15:38:28 +00:00
|
|
|
int i = 0, j = 0, kw, base_style = 0, has_space;
|
2014-01-10 01:25:14 +00:00
|
|
|
|
2014-04-02 12:58:12 +00:00
|
|
|
if (colstate & IN_ORG_BLOCK) {
|
2014-01-20 18:04:00 +00:00
|
|
|
for (j = i; str[j] == ' '; )
|
2014-01-10 01:25:14 +00:00
|
|
|
j++;
|
2014-01-20 18:04:00 +00:00
|
|
|
if (ustristart(str + j, "#+end_", NULL)) {
|
2014-04-02 12:58:12 +00:00
|
|
|
colstate &= ~(IN_ORG_BLOCK | IN_ORG_LISP);
|
2014-01-10 01:25:14 +00:00
|
|
|
} else {
|
2014-04-02 12:58:12 +00:00
|
|
|
if (colstate & IN_ORG_LISP) {
|
|
|
|
|
colstate &= ~(IN_ORG_LISP | IN_ORG_BLOCK);
|
2014-04-05 15:49:14 +00:00
|
|
|
cp->colorize_state = colstate;
|
2024-07-27 23:15:54 +02:00
|
|
|
cp_colorize_line(cp, str, 0, n, sbuf, &lisp_mode);
|
2014-04-05 15:49:14 +00:00
|
|
|
colstate = cp->colorize_state;
|
2014-04-02 12:58:12 +00:00
|
|
|
colstate |= IN_ORG_LISP | IN_ORG_BLOCK;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
2014-04-05 15:49:14 +00:00
|
|
|
cp->colorize_state = colstate;
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-11 15:38:28 +00:00
|
|
|
if (str[i] == '*') {
|
|
|
|
|
/* Check for heading: initial string of '*' followed by ' ' */
|
2014-01-20 18:04:00 +00:00
|
|
|
for (j = i + 1; str[j] == '*'; j++)
|
2014-01-11 15:38:28 +00:00
|
|
|
continue;
|
2014-01-10 01:25:14 +00:00
|
|
|
|
2014-01-20 18:04:00 +00:00
|
|
|
if (str[j] == ' ') {
|
2014-01-11 15:38:28 +00:00
|
|
|
base_style = OrgBulletStyles[(j - i - 1) % BULLET_STYLES];
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, j + 1, base_style);
|
2014-01-11 15:38:28 +00:00
|
|
|
i = j + 1;
|
2014-01-10 01:25:14 +00:00
|
|
|
|
2014-01-20 18:04:00 +00:00
|
|
|
kw = org_todo_keyword(str + i);
|
2014-01-11 15:38:28 +00:00
|
|
|
if (kw > -1) {
|
|
|
|
|
j = i + strlen(OrgTodoKeywords[kw].keyword) + 1;
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, j, OrgTodoKeywords[kw].style);
|
2014-01-11 15:38:28 +00:00
|
|
|
i = j;
|
|
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
2014-01-10 01:25:14 +00:00
|
|
|
} else {
|
2014-01-20 18:04:00 +00:00
|
|
|
while (str[i] == ' ')
|
2014-01-10 01:25:14 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
if (str[i] == '#') {
|
2014-01-20 18:04:00 +00:00
|
|
|
if (str[i + 1] == ' ') { /* [ \t]*[#][ ] -> comment */
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, n, ORG_STYLE_COMMENT);
|
2014-01-10 01:25:14 +00:00
|
|
|
i = n;
|
|
|
|
|
} else
|
2014-01-20 18:04:00 +00:00
|
|
|
if (str[i + 1] == '+') { /* [ \t]*[#][+] -> metadata */
|
2014-01-10 01:25:14 +00:00
|
|
|
/* Should interpret litteral examples:
|
|
|
|
|
* #+BEGIN_xxx / #+END_xxx
|
|
|
|
|
* #+BEGIN_LATEX / #+END_LATEX
|
|
|
|
|
* #+BEGIN_SRC / #+END_SRC
|
|
|
|
|
*/
|
2014-01-20 18:04:00 +00:00
|
|
|
if (ustristart(str + i, "#+begin_", NULL)) {
|
2014-04-02 12:58:12 +00:00
|
|
|
colstate |= IN_ORG_BLOCK;
|
2014-01-20 18:04:00 +00:00
|
|
|
if (ustristr(str + i, "lisp")) {
|
2014-04-02 12:58:12 +00:00
|
|
|
colstate |= IN_ORG_LISP;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, n, ORG_STYLE_PREPROCESS);
|
2014-01-10 01:25:14 +00:00
|
|
|
i = n;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
if (str[i] == ':') {
|
|
|
|
|
if (str[i + 1] == ' ') {
|
|
|
|
|
/* code snipplet, should use code colorizer */
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, n, ORG_STYLE_CODE);
|
2014-01-10 01:25:14 +00:00
|
|
|
i = n;
|
|
|
|
|
} else {
|
|
|
|
|
/* property */
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, n, ORG_STYLE_PROPERTY);
|
2014-01-10 01:25:14 +00:00
|
|
|
i = n;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
if (str[i] == '-') {
|
|
|
|
|
/* five or more dashes indicate a horizontal bar */
|
|
|
|
|
} else
|
|
|
|
|
if (str[i] == '|') {
|
2014-04-02 12:58:12 +00:00
|
|
|
colstate |= IN_ORG_TABLE;
|
|
|
|
|
base_style = ORG_STYLE_TABLE;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-11 15:38:28 +00:00
|
|
|
has_space = 1;
|
|
|
|
|
|
2014-01-20 18:04:00 +00:00
|
|
|
for (;;) {
|
2014-01-10 01:25:14 +00:00
|
|
|
int chunk = 0;
|
2022-10-29 19:43:38 +02:00
|
|
|
char32_t c = str[i];
|
2014-01-10 01:25:14 +00:00
|
|
|
|
2014-01-20 18:04:00 +00:00
|
|
|
if (c == '\0')
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-11 15:38:28 +00:00
|
|
|
if (has_space || c == '\\') {
|
|
|
|
|
switch (c) {
|
|
|
|
|
case '#':
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
2014-01-11 15:38:28 +00:00
|
|
|
case '*': /* bold */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "*", "*", 1);
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
2014-01-11 15:38:28 +00:00
|
|
|
case '/': /* italic */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "/", "/", 1);
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
2014-01-11 15:38:28 +00:00
|
|
|
case '_': /* underline */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "_", "_", 1);
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
2014-01-11 15:38:28 +00:00
|
|
|
case '=': /* code */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "=", "=", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
break;
|
|
|
|
|
case '~': /* verbatim */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "~", "~", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
break;
|
|
|
|
|
case '+': /* strike-through */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "+", "+", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
break;
|
|
|
|
|
case '@': /* litteral stuff @@...@@ */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "@@", "@@", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
break;
|
|
|
|
|
case '[': /* wiki syntax for links [[...]..[...]] */
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "[[", "]]", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
break;
|
|
|
|
|
case '{': /* LaTeX syntax for macros {{{...}}} and {} */
|
|
|
|
|
if (str[i + 1] == '}')
|
|
|
|
|
chunk = 2;
|
|
|
|
|
else
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "{{{", "}}}", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
break;
|
|
|
|
|
case '\\': /* TeX syntax: \keyword \- \[ \] \( \) */
|
|
|
|
|
if (str[i + 1] == '\\') { /* \\ escape */
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, i + 2, base_style);
|
2014-01-11 15:38:28 +00:00
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (str[i + 1] == '-') {
|
|
|
|
|
chunk = 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-01-20 18:04:00 +00:00
|
|
|
for (chunk = 1; qe_isalnum(str[i + chunk]); chunk++) {
|
2014-01-11 15:38:28 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (chunk > 0)
|
|
|
|
|
break;
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "\\(", "\\)", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
if (chunk > 0)
|
|
|
|
|
break;
|
2014-01-20 18:04:00 +00:00
|
|
|
chunk = org_scan_chunk(str + i, "\\[", "\\]", 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
if (chunk > 0)
|
|
|
|
|
break;
|
|
|
|
|
break;
|
|
|
|
|
case '-': /* Colorize special glyphs -- and --- */
|
2014-01-10 01:25:14 +00:00
|
|
|
if (str[i + 1] == '-') {
|
|
|
|
|
chunk = 2;
|
|
|
|
|
if (str[i + 2] == '-')
|
|
|
|
|
chunk++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-01-11 15:38:28 +00:00
|
|
|
break;
|
|
|
|
|
case '.': /* Colorize special glyph ... */
|
|
|
|
|
if (str[i + 1] == '.' && str[i + 2] == '.') {
|
|
|
|
|
chunk = 3;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ' ':
|
|
|
|
|
has_space = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
has_space = 0;
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2014-01-11 15:38:28 +00:00
|
|
|
} else {
|
|
|
|
|
has_space = (str[i] == ' ');
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
2014-01-10 01:25:14 +00:00
|
|
|
if (chunk) {
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE(sbuf, i, i + chunk, ORG_STYLE_EMPHASIS);
|
2014-01-10 01:25:14 +00:00
|
|
|
i += chunk;
|
|
|
|
|
} else {
|
2024-07-27 23:15:54 +02:00
|
|
|
SET_STYLE1(sbuf, i, base_style);
|
2014-01-10 01:25:14 +00:00
|
|
|
i++;
|
|
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-02 12:58:12 +00:00
|
|
|
colstate &= ~IN_ORG_TABLE;
|
2014-04-05 15:49:14 +00:00
|
|
|
cp->colorize_state = colstate;
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-10 14:00:08 +00:00
|
|
|
static int org_is_header_line(EditState *s, int offset)
|
|
|
|
|
{
|
|
|
|
|
/* Check if line starts with '*' */
|
|
|
|
|
/* XXX: should ignore blocks using colorstate */
|
|
|
|
|
return eb_nextc(s->b, eb_goto_bol(s->b, offset), &offset) == '*';
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
static int org_find_heading(EditState *s, int offset, int *level, int silent)
|
2014-01-07 18:26:07 +00:00
|
|
|
{
|
2022-10-29 19:43:38 +02:00
|
|
|
int offset1, nb;
|
|
|
|
|
char32_t c;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
offset = eb_goto_bol(s->b, offset);
|
2014-01-08 16:26:44 +00:00
|
|
|
for (;;) {
|
2014-01-10 01:25:14 +00:00
|
|
|
/* Find line starting with '*' */
|
|
|
|
|
/* XXX: should ignore blocks using colorstate */
|
|
|
|
|
if (eb_nextc(s->b, offset, &offset1) == '*') {
|
|
|
|
|
for (nb = 1; (c = eb_nextc(s->b, offset1, &offset1)) == '*'; nb++)
|
|
|
|
|
continue;
|
|
|
|
|
if (c == ' ') {
|
|
|
|
|
*level = nb;
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
2014-01-08 16:26:44 +00:00
|
|
|
if (offset == 0)
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
|
|
|
|
offset = eb_prev_line(s->b, offset);
|
|
|
|
|
}
|
2014-01-29 23:24:00 +00:00
|
|
|
if (!silent)
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Before first heading");
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int org_next_heading(EditState *s, int offset, int target, int *level)
|
|
|
|
|
{
|
2022-10-29 19:43:38 +02:00
|
|
|
int offset1, nb;
|
|
|
|
|
char32_t c;
|
2014-01-10 01:25:14 +00:00
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
offset = eb_next_line(s->b, offset);
|
2014-01-10 14:00:08 +00:00
|
|
|
if (offset >= s->b->total_size) {
|
|
|
|
|
nb = 0;
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
2014-01-10 14:00:08 +00:00
|
|
|
}
|
2014-01-10 01:25:14 +00:00
|
|
|
/* XXX: should ignore blocks using colorstate */
|
|
|
|
|
if (eb_nextc(s->b, offset, &offset1) == '*') {
|
|
|
|
|
for (nb = 1; (c = eb_nextc(s->b, offset1, &offset1)) == '*'; nb++)
|
|
|
|
|
continue;
|
|
|
|
|
if (c == ' ' && nb <= target) {
|
2014-01-10 14:00:08 +00:00
|
|
|
break;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-10 14:00:08 +00:00
|
|
|
if (level)
|
|
|
|
|
*level = nb;
|
|
|
|
|
return offset;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int org_prev_heading(EditState *s, int offset, int target, int *level)
|
|
|
|
|
{
|
2022-10-29 19:43:38 +02:00
|
|
|
int offset1, nb;
|
|
|
|
|
char32_t c;
|
2014-01-08 16:26:44 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
for (;;) {
|
2014-01-10 14:00:08 +00:00
|
|
|
if (offset == 0) {
|
|
|
|
|
nb = 0;
|
2014-01-10 01:25:14 +00:00
|
|
|
break;
|
2014-01-10 14:00:08 +00:00
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
offset = eb_prev_line(s->b, offset);
|
2014-01-10 01:25:14 +00:00
|
|
|
/* XXX: should ignore blocks using colorstate */
|
|
|
|
|
if (eb_nextc(s->b, offset, &offset1) == '*') {
|
|
|
|
|
for (nb = 1; (c = eb_nextc(s->b, offset1, &offset1)) == '*'; nb++)
|
|
|
|
|
continue;
|
|
|
|
|
if (c == ' ' && nb <= target) {
|
2014-01-10 14:00:08 +00:00
|
|
|
break;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-01-08 16:26:44 +00:00
|
|
|
}
|
2014-01-10 14:00:08 +00:00
|
|
|
if (level)
|
|
|
|
|
*level = nb;
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_outline_next_vsible_heading(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
s->offset = org_next_heading(s, s->offset, MAX_LEVEL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_outline_previous_vsible_heading(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
s->offset = org_prev_heading(s, s->offset, MAX_LEVEL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_outline_up_heading(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
int offset, level;
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-10 14:00:08 +00:00
|
|
|
return;
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-10 14:00:08 +00:00
|
|
|
if (level <= 1) {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Already at top level of the outline");
|
2014-01-10 14:00:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s->offset = org_prev_heading(s, offset, level - 1, &level);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_backward_same_level(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
int offset, level, level1;
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-10 14:00:08 +00:00
|
|
|
return;
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-10 14:00:08 +00:00
|
|
|
offset = org_prev_heading(s, offset, level, &level1);
|
|
|
|
|
if (level1 != level) {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "No previous same-level heading");
|
2014-01-10 14:00:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
s->offset = offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_forward_same_level(EditState *s)
|
|
|
|
|
{
|
|
|
|
|
int offset, level, level1;
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-10 14:00:08 +00:00
|
|
|
return;
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-10 14:00:08 +00:00
|
|
|
offset = org_next_heading(s, offset, level, &level1);
|
|
|
|
|
if (level1 != level) {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "No following same-level heading");
|
2014-01-10 14:00:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
s->offset = offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_goto(EditState *s, const char *dest)
|
|
|
|
|
{
|
|
|
|
|
int offset, level, level1, nb;
|
|
|
|
|
const char *p = dest;
|
|
|
|
|
|
|
|
|
|
/* XXX: Should pop up a window with numbered outline index
|
|
|
|
|
* and let the user select the target interactively.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Jump to numbered destination. */
|
|
|
|
|
for (offset = 0, level = 0; qe_isdigit(*p); ) {
|
2022-08-10 18:50:19 +02:00
|
|
|
nb = strtol_c(p, &p, 10);
|
2014-01-10 14:00:08 +00:00
|
|
|
if (*p == '.')
|
|
|
|
|
p++;
|
|
|
|
|
level++;
|
|
|
|
|
for (; nb > 0; nb--) {
|
|
|
|
|
offset = org_next_heading(s, offset, level, &level1);
|
|
|
|
|
if (level != level1) {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Heading not found");
|
2014-01-10 14:00:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (level)
|
|
|
|
|
s->offset = offset;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-11 15:38:28 +00:00
|
|
|
static void do_org_mark_element(EditState *s, int subtree)
|
|
|
|
|
{
|
Remove references to global `qe_state` (#45)
* Remove references to global `qe_state`
Add `QEmacsState *qs` field in context and object structures:
- `QEditScreen`, `EditState` (renamed from `qe_state`), `QuitState`
- `WinWindow` (win32.c), `X11State` (x11.c), `QEArgs` (cmd line arguments)
- `CmdLineOptionDef::func_arg()`, `QEModeData`
- move `QEKeyContext` to `QEmacsState`
Pass `QEmacsState *qs` to configuration and state functions:
- all `module_xxx_init` and static `xxx_init` functions
- `QEDisplay::dpy_init()`, `qe_register_display()`, `screen_init()̀`
- `load_input_methods()`, `unload_input_methods()`
- `register_input_method()`, `find_input_method()`
- `find_resource_file()`, `open_resource_file()`
- `qe_find_current_binding()`, `qe_list_bindings()`
- `qe_register_mode()`, `qe_find_mode()`, `qe_find_mode_filename()`
- `qe_register_cmd_line_options()`, `set_user_option()`, `set_tty_charset()`
- `qe_register_commands()`, `qe_register_bindings()`, `qe_find_cmd()`
- `qe_register_completion()`, `qe_register_variables()`
- `eb_register_data_type()`, `parse_command_line()`
- `eb_trace_bytes()`, `qe_toggle_control_h()` (split from `do_toggle_control_h()`)
- `unget_key()`, `qe_grab_keys()`, `qe_ungrab_keys()`, `qe_key_process()`
- `eb_new()`, `eb_find()`, `eb_find_new()`, `eb_scratch()`, `eb_find_file()`
- `new_shell_buffer()` `macro_add_key()`, `clear_macro(), `stop_macro()`
- `check_window()`, `check_buffer()`, `qe_kill_buffer()`, `qe_get_history()`
- `qe_register_charset()`, `find_charset()`
Add error message handlers:
- add `QEDisplay::dpy_error()` method
- add `qe_cfg_error()`, use for all expression parsing errors
- pass opaque pointer to `css_error()`
- add `qe_put_error()` and `qe_dpy_error()`
Add context argument:
- always pass a non-null window pointer to `do_refresh()`, `new_help_buffer()`
Rename functions:
- `find_resource_file` -> `qe_find_resource_file`
- `open_resource_file` -> `qe_open_resource_file`
- `input_methods_init` -> `qe_input_methods_init`
- `load_input_methods` -> `qe_load_input_methods`
- `unload_input_methods` -> `qe_unload_input_methods`
- `find_input_methods` -> `qe_find_input_methods`
- `register_input_method` -> `qe_register_input_method`
- `parse_command_line` -> `qe_parse_command_line`
- `eb_trace_bytes` -> `qe_trace_bytes`
- `eb_init` -> `qe_data_init`
- `eb_count_buffers` -> `qe_count_buffers`
- `eb_get_buffer_from_index` -> `qe_get_buffer_from_index`
- `init_all_modules` -> `qe_init_all_modules`
- `exit_all_modules` -> `qe_exit_all_modules`
- `load_all_modules` -> `qe_load_all_modules`
- `maybe_set_mark` -> `do_maybe_set_mark`
- `unget_key` -> `qe_unget_key`
- `minibuffer_init` -> `qe_minibuffer_init`
- `edit_display` -> `qe_display`
- `new_yank_buffer` -> `qe_new_yank_buffer`
- `new_shell_buffer` -> `qe_new_shell_buffer`
- `shell_find_mode` -> `qe_shell_find_mode`
- `save_selection` -> `qe_save_selection`
- `register_emulation_bindings` -> `qe_register_emulation_bindings`
- `macro_add_key` -> `qe_macro_add_key`
- `clear_macro` -> `qe_clear_macro`
- `stop_macro` -> `qe_stop_macro`
- `eb_format_message` -> `qe_format_message`
- `screen_init` -> `qe_screen_init`
- `charset_jis_init` -> `qe_charset_jis_init`
- `charset_more_init` -> `qe_charset_more_init`
- `check_window` -> `qe_check_window`
- `check_buffer` -> `qe_check_buffer`
- `eb_find_file` -> `qe_find_buffer_file`
- `eb_find` -> `qe_find_buffer_name`
- `eb_new` -> `qe_new_buffer`
- `eb_find_new` -> `qe_new_buffer` with `BC_REUSE`
- `eb_scratch` -> `qe_new_buffer` with `BC_REUSE | BC_CLEAR`
- `find_charset` -> `qe_find_charset`
Add asan, msan and ubsan targets
Fix `qe_encode64` buffer length computation.
Add `qe_new_shell_buffer` flags `SF_REUSE_BUFFER` and `SF_ERASE_BUFFER`
Bumped version to 6.3.3
fix redundant typedef
fix compilation errors
2024-12-01 23:34:00 +01:00
|
|
|
QEmacsState *qs = s->qs;
|
2014-01-11 15:38:28 +00:00
|
|
|
int offset, offset1, level;
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-11 15:38:28 +00:00
|
|
|
return;
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-11 15:38:28 +00:00
|
|
|
offset1 = org_next_heading(s, offset, subtree ? level : MAX_LEVEL, NULL);
|
|
|
|
|
|
|
|
|
|
/* XXX: if repeating last command, add subtree to region */
|
|
|
|
|
if (qs->last_cmd_func != qs->this_cmd_func)
|
|
|
|
|
s->b->mark = offset;
|
|
|
|
|
|
|
|
|
|
s->offset = offset1;
|
|
|
|
|
/* activate region hilite */
|
Remove references to global `qe_state` (#45)
* Remove references to global `qe_state`
Add `QEmacsState *qs` field in context and object structures:
- `QEditScreen`, `EditState` (renamed from `qe_state`), `QuitState`
- `WinWindow` (win32.c), `X11State` (x11.c), `QEArgs` (cmd line arguments)
- `CmdLineOptionDef::func_arg()`, `QEModeData`
- move `QEKeyContext` to `QEmacsState`
Pass `QEmacsState *qs` to configuration and state functions:
- all `module_xxx_init` and static `xxx_init` functions
- `QEDisplay::dpy_init()`, `qe_register_display()`, `screen_init()̀`
- `load_input_methods()`, `unload_input_methods()`
- `register_input_method()`, `find_input_method()`
- `find_resource_file()`, `open_resource_file()`
- `qe_find_current_binding()`, `qe_list_bindings()`
- `qe_register_mode()`, `qe_find_mode()`, `qe_find_mode_filename()`
- `qe_register_cmd_line_options()`, `set_user_option()`, `set_tty_charset()`
- `qe_register_commands()`, `qe_register_bindings()`, `qe_find_cmd()`
- `qe_register_completion()`, `qe_register_variables()`
- `eb_register_data_type()`, `parse_command_line()`
- `eb_trace_bytes()`, `qe_toggle_control_h()` (split from `do_toggle_control_h()`)
- `unget_key()`, `qe_grab_keys()`, `qe_ungrab_keys()`, `qe_key_process()`
- `eb_new()`, `eb_find()`, `eb_find_new()`, `eb_scratch()`, `eb_find_file()`
- `new_shell_buffer()` `macro_add_key()`, `clear_macro(), `stop_macro()`
- `check_window()`, `check_buffer()`, `qe_kill_buffer()`, `qe_get_history()`
- `qe_register_charset()`, `find_charset()`
Add error message handlers:
- add `QEDisplay::dpy_error()` method
- add `qe_cfg_error()`, use for all expression parsing errors
- pass opaque pointer to `css_error()`
- add `qe_put_error()` and `qe_dpy_error()`
Add context argument:
- always pass a non-null window pointer to `do_refresh()`, `new_help_buffer()`
Rename functions:
- `find_resource_file` -> `qe_find_resource_file`
- `open_resource_file` -> `qe_open_resource_file`
- `input_methods_init` -> `qe_input_methods_init`
- `load_input_methods` -> `qe_load_input_methods`
- `unload_input_methods` -> `qe_unload_input_methods`
- `find_input_methods` -> `qe_find_input_methods`
- `register_input_method` -> `qe_register_input_method`
- `parse_command_line` -> `qe_parse_command_line`
- `eb_trace_bytes` -> `qe_trace_bytes`
- `eb_init` -> `qe_data_init`
- `eb_count_buffers` -> `qe_count_buffers`
- `eb_get_buffer_from_index` -> `qe_get_buffer_from_index`
- `init_all_modules` -> `qe_init_all_modules`
- `exit_all_modules` -> `qe_exit_all_modules`
- `load_all_modules` -> `qe_load_all_modules`
- `maybe_set_mark` -> `do_maybe_set_mark`
- `unget_key` -> `qe_unget_key`
- `minibuffer_init` -> `qe_minibuffer_init`
- `edit_display` -> `qe_display`
- `new_yank_buffer` -> `qe_new_yank_buffer`
- `new_shell_buffer` -> `qe_new_shell_buffer`
- `shell_find_mode` -> `qe_shell_find_mode`
- `save_selection` -> `qe_save_selection`
- `register_emulation_bindings` -> `qe_register_emulation_bindings`
- `macro_add_key` -> `qe_macro_add_key`
- `clear_macro` -> `qe_clear_macro`
- `stop_macro` -> `qe_stop_macro`
- `eb_format_message` -> `qe_format_message`
- `screen_init` -> `qe_screen_init`
- `charset_jis_init` -> `qe_charset_jis_init`
- `charset_more_init` -> `qe_charset_more_init`
- `check_window` -> `qe_check_window`
- `check_buffer` -> `qe_check_buffer`
- `eb_find_file` -> `qe_find_buffer_file`
- `eb_find` -> `qe_find_buffer_name`
- `eb_new` -> `qe_new_buffer`
- `eb_find_new` -> `qe_new_buffer` with `BC_REUSE`
- `eb_scratch` -> `qe_new_buffer` with `BC_REUSE | BC_CLEAR`
- `find_charset` -> `qe_find_charset`
Add asan, msan and ubsan targets
Fix `qe_encode64` buffer length computation.
Add `qe_new_shell_buffer` flags `SF_REUSE_BUFFER` and `SF_ERASE_BUFFER`
Bumped version to 6.3.3
fix redundant typedef
fix compilation errors
2024-12-01 23:34:00 +01:00
|
|
|
if (s->qs->hilite_region)
|
2014-01-11 15:38:28 +00:00
|
|
|
s->region_style = QE_STYLE_REGION_HILITE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
static void do_org_todo(EditState *s)
|
|
|
|
|
{
|
2014-01-11 15:38:28 +00:00
|
|
|
int offset, offset1, bullets, kw;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
if (check_read_only(s))
|
|
|
|
|
return;
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &bullets, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
offset = eb_skip_chars(s->b, offset, bullets + 1);
|
2014-01-11 15:38:28 +00:00
|
|
|
for (kw = 0; kw < countof(OrgTodoKeywords); kw++) {
|
2022-11-01 01:19:32 +01:00
|
|
|
if (eb_match_str_utf8(s->b, offset, OrgTodoKeywords[kw].keyword, &offset1)
|
2022-10-29 19:43:38 +02:00
|
|
|
&& eb_match_char32(s->b, offset1, ' ', &offset1)) {
|
2014-01-11 15:38:28 +00:00
|
|
|
eb_delete_range(s->b, offset, offset1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
2014-01-11 15:38:28 +00:00
|
|
|
if (kw == countof(OrgTodoKeywords))
|
|
|
|
|
kw = 0;
|
|
|
|
|
else
|
|
|
|
|
kw++;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
|
|
|
|
if (kw < countof(OrgTodoKeywords)) {
|
2014-01-11 15:38:28 +00:00
|
|
|
offset += eb_insert_str(s->b, offset, OrgTodoKeywords[kw].keyword);
|
2022-10-29 19:43:38 +02:00
|
|
|
eb_insert_char32(s->b, offset, ' ');
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 14:00:08 +00:00
|
|
|
static void do_org_insert_heading(EditState *s, int flags)
|
2014-01-10 01:25:14 +00:00
|
|
|
{
|
|
|
|
|
int offset, offset0, offset1, level = 1;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
if (check_read_only(s))
|
|
|
|
|
return;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 1);
|
2014-01-10 01:25:14 +00:00
|
|
|
offset0 = eb_goto_bol(s->b, s->offset);
|
|
|
|
|
offset1 = eb_goto_eol(s->b, s->offset);
|
|
|
|
|
|
|
|
|
|
/* if at beginning of heading line, insert sibling heading before,
|
|
|
|
|
* if in the middle of a heading line, split the heading,
|
|
|
|
|
* otherwise, make the current line a heading line at current level.
|
|
|
|
|
*/
|
2014-01-10 14:00:08 +00:00
|
|
|
if (flags & 2) {
|
|
|
|
|
/* respect-content: insert heading at end of subtree */
|
|
|
|
|
offset = org_next_heading(s, offset, level, NULL);
|
2022-10-29 19:43:38 +02:00
|
|
|
eb_insert_char32_n(s->b, offset, '\n', 2);
|
2014-01-10 14:00:08 +00:00
|
|
|
} else
|
2014-01-10 01:25:14 +00:00
|
|
|
if (s->offset <= offset + level + 1) {
|
2022-10-29 19:43:38 +02:00
|
|
|
eb_insert_char32(s->b, offset, '\n');
|
2014-01-10 01:25:14 +00:00
|
|
|
} else
|
|
|
|
|
if (offset == offset0 || offset == offset1) {
|
|
|
|
|
offset = s->offset;
|
2022-10-29 19:43:38 +02:00
|
|
|
offset += eb_insert_char32(s->b, offset, '\n');
|
2014-01-10 01:25:14 +00:00
|
|
|
} else {
|
|
|
|
|
offset = offset0;
|
2015-08-27 23:03:39 +00:00
|
|
|
}
|
2014-03-21 20:49:30 +00:00
|
|
|
offset1 = offset;
|
2022-10-29 19:43:38 +02:00
|
|
|
while (eb_match_char32(s->b, offset1, ' ', &offset1))
|
2014-03-21 20:49:30 +00:00
|
|
|
continue;
|
|
|
|
|
eb_delete(s->b, offset, offset1 - offset);
|
|
|
|
|
|
2022-10-29 19:43:38 +02:00
|
|
|
offset += eb_insert_char32_n(s->b, offset, '*', level);
|
|
|
|
|
offset += eb_insert_char32(s->b, offset, ' ');
|
2014-01-10 01:25:14 +00:00
|
|
|
s->offset = eb_goto_eol(s->b, offset);
|
2014-01-10 14:00:08 +00:00
|
|
|
if (flags & 1) {
|
|
|
|
|
/* insert-todo-heading */
|
|
|
|
|
do_org_todo(s);
|
|
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_promote(EditState *s, int dir)
|
|
|
|
|
{
|
2014-01-10 01:25:14 +00:00
|
|
|
int offset, level;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
if (check_read_only(s))
|
2014-01-07 18:26:07 +00:00
|
|
|
return;
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
if (dir < 0) {
|
2022-10-29 19:43:38 +02:00
|
|
|
eb_insert_char32(s->b, offset, '*');
|
2014-01-10 01:25:14 +00:00
|
|
|
} else
|
|
|
|
|
if (dir > 0) {
|
|
|
|
|
if (level > 1)
|
2022-10-29 19:43:38 +02:00
|
|
|
eb_delete_char32(s->b, offset);
|
2014-01-10 01:25:14 +00:00
|
|
|
else
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Cannot promote to level 0");
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_promote_subtree(EditState *s, int dir)
|
|
|
|
|
{
|
2014-01-10 01:25:14 +00:00
|
|
|
int offset, level, level1;
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
if (check_read_only(s))
|
2014-01-07 18:26:07 +00:00
|
|
|
return;
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-07 18:26:07 +00:00
|
|
|
return;
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-07 18:26:07 +00:00
|
|
|
for (;;) {
|
2014-01-10 01:25:14 +00:00
|
|
|
if (dir < 0) {
|
2022-10-29 19:43:38 +02:00
|
|
|
eb_insert_char32(s->b, offset, '*');
|
2014-01-10 01:25:14 +00:00
|
|
|
} else
|
|
|
|
|
if (dir > 0) {
|
|
|
|
|
if (level > 1) {
|
2022-10-29 19:43:38 +02:00
|
|
|
eb_delete_char32(s->b, offset);
|
2014-01-10 01:25:14 +00:00
|
|
|
} else {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Cannot promote to level 0");
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
offset = org_next_heading(s, offset, MAX_LEVEL, &level1);
|
2014-01-10 14:00:08 +00:00
|
|
|
if (level1 <= level)
|
2014-01-07 18:26:07 +00:00
|
|
|
break;
|
2014-01-10 01:25:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-01-07 18:26:07 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
static void do_org_move_subtree(EditState *s, int dir)
|
|
|
|
|
{
|
|
|
|
|
int offset, offset1, offset2, level, level1, level2, size;
|
|
|
|
|
EditBuffer *b1;
|
|
|
|
|
|
|
|
|
|
if (check_read_only(s))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!org_is_header_line(s, s->offset)) {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Not on header line");
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-29 23:24:00 +00:00
|
|
|
offset = org_find_heading(s, s->offset, &level, 0);
|
|
|
|
|
if (offset < 0)
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
2014-01-29 23:24:00 +00:00
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
offset1 = org_next_heading(s, offset, level, &level1);
|
|
|
|
|
size = offset1 - offset;
|
|
|
|
|
|
|
|
|
|
if (dir < 0) {
|
|
|
|
|
offset2 = org_prev_heading(s, offset, level, &level2);
|
2014-01-10 14:00:08 +00:00
|
|
|
if (level2 < level) {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Cannot move substree");
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (offset1 == s->b->total_size || level1 < level) {
|
2024-12-03 22:52:55 +01:00
|
|
|
put_error(s, "Cannot move substree");
|
2014-01-10 01:25:14 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
offset2 = org_next_heading(s, offset1, level, &level2);
|
|
|
|
|
}
|
Remove references to global `qe_state` (#45)
* Remove references to global `qe_state`
Add `QEmacsState *qs` field in context and object structures:
- `QEditScreen`, `EditState` (renamed from `qe_state`), `QuitState`
- `WinWindow` (win32.c), `X11State` (x11.c), `QEArgs` (cmd line arguments)
- `CmdLineOptionDef::func_arg()`, `QEModeData`
- move `QEKeyContext` to `QEmacsState`
Pass `QEmacsState *qs` to configuration and state functions:
- all `module_xxx_init` and static `xxx_init` functions
- `QEDisplay::dpy_init()`, `qe_register_display()`, `screen_init()̀`
- `load_input_methods()`, `unload_input_methods()`
- `register_input_method()`, `find_input_method()`
- `find_resource_file()`, `open_resource_file()`
- `qe_find_current_binding()`, `qe_list_bindings()`
- `qe_register_mode()`, `qe_find_mode()`, `qe_find_mode_filename()`
- `qe_register_cmd_line_options()`, `set_user_option()`, `set_tty_charset()`
- `qe_register_commands()`, `qe_register_bindings()`, `qe_find_cmd()`
- `qe_register_completion()`, `qe_register_variables()`
- `eb_register_data_type()`, `parse_command_line()`
- `eb_trace_bytes()`, `qe_toggle_control_h()` (split from `do_toggle_control_h()`)
- `unget_key()`, `qe_grab_keys()`, `qe_ungrab_keys()`, `qe_key_process()`
- `eb_new()`, `eb_find()`, `eb_find_new()`, `eb_scratch()`, `eb_find_file()`
- `new_shell_buffer()` `macro_add_key()`, `clear_macro(), `stop_macro()`
- `check_window()`, `check_buffer()`, `qe_kill_buffer()`, `qe_get_history()`
- `qe_register_charset()`, `find_charset()`
Add error message handlers:
- add `QEDisplay::dpy_error()` method
- add `qe_cfg_error()`, use for all expression parsing errors
- pass opaque pointer to `css_error()`
- add `qe_put_error()` and `qe_dpy_error()`
Add context argument:
- always pass a non-null window pointer to `do_refresh()`, `new_help_buffer()`
Rename functions:
- `find_resource_file` -> `qe_find_resource_file`
- `open_resource_file` -> `qe_open_resource_file`
- `input_methods_init` -> `qe_input_methods_init`
- `load_input_methods` -> `qe_load_input_methods`
- `unload_input_methods` -> `qe_unload_input_methods`
- `find_input_methods` -> `qe_find_input_methods`
- `register_input_method` -> `qe_register_input_method`
- `parse_command_line` -> `qe_parse_command_line`
- `eb_trace_bytes` -> `qe_trace_bytes`
- `eb_init` -> `qe_data_init`
- `eb_count_buffers` -> `qe_count_buffers`
- `eb_get_buffer_from_index` -> `qe_get_buffer_from_index`
- `init_all_modules` -> `qe_init_all_modules`
- `exit_all_modules` -> `qe_exit_all_modules`
- `load_all_modules` -> `qe_load_all_modules`
- `maybe_set_mark` -> `do_maybe_set_mark`
- `unget_key` -> `qe_unget_key`
- `minibuffer_init` -> `qe_minibuffer_init`
- `edit_display` -> `qe_display`
- `new_yank_buffer` -> `qe_new_yank_buffer`
- `new_shell_buffer` -> `qe_new_shell_buffer`
- `shell_find_mode` -> `qe_shell_find_mode`
- `save_selection` -> `qe_save_selection`
- `register_emulation_bindings` -> `qe_register_emulation_bindings`
- `macro_add_key` -> `qe_macro_add_key`
- `clear_macro` -> `qe_clear_macro`
- `stop_macro` -> `qe_stop_macro`
- `eb_format_message` -> `qe_format_message`
- `screen_init` -> `qe_screen_init`
- `charset_jis_init` -> `qe_charset_jis_init`
- `charset_more_init` -> `qe_charset_more_init`
- `check_window` -> `qe_check_window`
- `check_buffer` -> `qe_check_buffer`
- `eb_find_file` -> `qe_find_buffer_file`
- `eb_find` -> `qe_find_buffer_name`
- `eb_new` -> `qe_new_buffer`
- `eb_find_new` -> `qe_new_buffer` with `BC_REUSE`
- `eb_scratch` -> `qe_new_buffer` with `BC_REUSE | BC_CLEAR`
- `find_charset` -> `qe_find_charset`
Add asan, msan and ubsan targets
Fix `qe_encode64` buffer length computation.
Add `qe_new_shell_buffer` flags `SF_REUSE_BUFFER` and `SF_ERASE_BUFFER`
Bumped version to 6.3.3
fix redundant typedef
fix compilation errors
2024-12-01 23:34:00 +01:00
|
|
|
// XXX: should have a way to move buffer contents
|
|
|
|
|
b1 = qe_new_buffer(s->qs, "*tmp*", BF_SYSTEM | (s->b->flags & BF_STYLES));
|
|
|
|
|
if (!b1)
|
|
|
|
|
return;
|
2014-02-05 00:56:48 +00:00
|
|
|
eb_set_charset(b1, s->b->charset, s->b->eol_type);
|
2014-01-15 19:44:24 +00:00
|
|
|
eb_insert_buffer_convert(b1, 0, s->b, offset, size);
|
2014-01-10 01:25:14 +00:00
|
|
|
eb_delete(s->b, offset, size);
|
|
|
|
|
if (offset2 > offset)
|
|
|
|
|
offset2 -= size;
|
2014-01-15 19:44:24 +00:00
|
|
|
eb_insert_buffer_convert(s->b, offset2, b1, 0, b1->total_size);
|
2014-01-23 12:56:22 +00:00
|
|
|
eb_free(&b1);
|
2014-01-10 01:25:14 +00:00
|
|
|
s->offset = offset2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_meta_return(EditState *s)
|
|
|
|
|
{
|
2014-01-10 14:00:08 +00:00
|
|
|
do_org_insert_heading(s, 0);
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_metaleft(EditState *s)
|
|
|
|
|
{
|
2014-01-10 01:25:14 +00:00
|
|
|
if (org_is_header_line(s, s->offset))
|
2014-01-10 14:00:08 +00:00
|
|
|
do_org_promote(s, +1);
|
2014-01-10 01:25:14 +00:00
|
|
|
else
|
2020-11-08 00:47:24 +01:00
|
|
|
do_word_left_right(s, -1);
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void do_org_metaright(EditState *s)
|
|
|
|
|
{
|
2014-01-10 01:25:14 +00:00
|
|
|
if (org_is_header_line(s, s->offset))
|
2014-01-10 14:00:08 +00:00
|
|
|
do_org_promote(s, -1);
|
2014-01-10 01:25:14 +00:00
|
|
|
else
|
2020-11-08 00:47:24 +01:00
|
|
|
do_word_left_right(s, +1);
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
static void do_org_metadown(EditState *s)
|
2014-01-07 18:26:07 +00:00
|
|
|
{
|
2014-01-10 01:25:14 +00:00
|
|
|
do_org_move_subtree(s, +1);
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-10 01:25:14 +00:00
|
|
|
static void do_org_metaup(EditState *s)
|
2014-01-07 18:26:07 +00:00
|
|
|
{
|
2014-01-10 01:25:14 +00:00
|
|
|
do_org_move_subtree(s, -1);
|
2014-01-07 18:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Org mode specific commands */
|
2022-08-16 22:39:51 +02:00
|
|
|
static const CmdDef org_commands[] = {
|
2014-01-10 14:00:08 +00:00
|
|
|
/* Motion */
|
2022-08-19 12:13:52 +02:00
|
|
|
CMD0( "outline-next-visible-heading", "C-c C-n",
|
|
|
|
|
"",
|
|
|
|
|
do_outline_next_vsible_heading)
|
|
|
|
|
CMD0( "outline-previous-visible-heading", "C-c C-p",
|
|
|
|
|
"",
|
|
|
|
|
do_outline_previous_vsible_heading)
|
|
|
|
|
CMD0( "outline-up-heading", "C-c C-u",
|
|
|
|
|
"",
|
|
|
|
|
do_outline_up_heading)
|
|
|
|
|
CMD0( "org-backward-same-level", "C-c C-b",
|
|
|
|
|
"",
|
|
|
|
|
do_org_backward_same_level)
|
|
|
|
|
CMD0( "org-forward-same-level", "C-c C-f",
|
|
|
|
|
"",
|
|
|
|
|
do_org_forward_same_level)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD2( "org-goto", "C-c C-j",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
2022-08-16 22:39:51 +02:00
|
|
|
do_org_goto, ESs,
|
2022-08-19 12:13:52 +02:00
|
|
|
"s{select location to jump to: }[orgjump]|orgjump|")
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-mark-element", "M-h",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_mark_element, ESi, "v", 0)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-mark-subtree", "C-c @",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_mark_element, ESi, "v", 1)
|
2014-01-10 14:00:08 +00:00
|
|
|
/* Editing */
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD2( "org-todo", "C-c C-t",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_todo, ES, "*")
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-insert-heading", "", /* indirect through M-RET */
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_insert_heading, ESi, "*" "v", 0)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-insert-todo-heading", "", /* actually M-S-RET and C-c C-x M */
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_insert_heading, ESi, "*" "v", 1)
|
2024-10-11 06:46:21 +02:00
|
|
|
CMD3( "org-insert-heading-respect-content", "C-j, C-RET", /* actually C-RET */
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_insert_heading, ESi, "*" "v", 2)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-insert-todo-heading-respect-content", "", /* actually C-S-RET */
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_insert_heading, ESi, "*" "v", 3)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-do-demote", "",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_promote, ESi, "*" "v", -1)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-do-promote", "",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_promote, ESi, "*" "v", +1)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-demote-subtree", "C-x >", /* actually M-S-right | C-c C-x R */
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_promote_subtree, ESi, "*" "v", -1)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-promote-subtree", "C-x <", /* actually M-S-left | C-c C-x L */
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_promote_subtree, ESi, "*" "v", +1)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-move-subtree-down", "",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_move_subtree, ESi, "*" "v", +1)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "org-move-subtree-up", "",
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_move_subtree, ESi, "*" "v", -1)
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD2( "org-meta-return", "M-RET", /* Actually M-RET | C-c C-x m */
|
2022-08-19 12:13:52 +02:00
|
|
|
"",
|
|
|
|
|
do_org_meta_return, ES, "*")
|
|
|
|
|
CMD0( "org-metaleft", "ESC left", /* actually M-left | C-c C-x l */
|
|
|
|
|
"",
|
|
|
|
|
do_org_metaleft)
|
|
|
|
|
CMD0( "org-metaright", "ESC right", /* actually M-right | C-c C-x r */
|
|
|
|
|
"",
|
|
|
|
|
do_org_metaright)
|
|
|
|
|
CMD0( "org-metadown", "ESC down", /* actually M-down | C-c C-x d */
|
|
|
|
|
"",
|
|
|
|
|
do_org_metadown)
|
|
|
|
|
CMD0( "org-metaup", "ESC up", /* actually M-up | C-c C-x u */
|
|
|
|
|
"",
|
|
|
|
|
do_org_metaup)
|
2014-01-07 18:26:07 +00:00
|
|
|
};
|
|
|
|
|
|
2017-04-16 21:51:19 +00:00
|
|
|
static ModeDef org_mode = {
|
2014-05-29 18:29:14 +00:00
|
|
|
.name = "org",
|
|
|
|
|
.extensions = "org",
|
|
|
|
|
.colorize_func = org_colorize_line,
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-19 19:15:08 +02:00
|
|
|
static int org_init(QEmacsState *qs)
|
2014-01-07 18:26:07 +00:00
|
|
|
{
|
Remove references to global `qe_state` (#45)
* Remove references to global `qe_state`
Add `QEmacsState *qs` field in context and object structures:
- `QEditScreen`, `EditState` (renamed from `qe_state`), `QuitState`
- `WinWindow` (win32.c), `X11State` (x11.c), `QEArgs` (cmd line arguments)
- `CmdLineOptionDef::func_arg()`, `QEModeData`
- move `QEKeyContext` to `QEmacsState`
Pass `QEmacsState *qs` to configuration and state functions:
- all `module_xxx_init` and static `xxx_init` functions
- `QEDisplay::dpy_init()`, `qe_register_display()`, `screen_init()̀`
- `load_input_methods()`, `unload_input_methods()`
- `register_input_method()`, `find_input_method()`
- `find_resource_file()`, `open_resource_file()`
- `qe_find_current_binding()`, `qe_list_bindings()`
- `qe_register_mode()`, `qe_find_mode()`, `qe_find_mode_filename()`
- `qe_register_cmd_line_options()`, `set_user_option()`, `set_tty_charset()`
- `qe_register_commands()`, `qe_register_bindings()`, `qe_find_cmd()`
- `qe_register_completion()`, `qe_register_variables()`
- `eb_register_data_type()`, `parse_command_line()`
- `eb_trace_bytes()`, `qe_toggle_control_h()` (split from `do_toggle_control_h()`)
- `unget_key()`, `qe_grab_keys()`, `qe_ungrab_keys()`, `qe_key_process()`
- `eb_new()`, `eb_find()`, `eb_find_new()`, `eb_scratch()`, `eb_find_file()`
- `new_shell_buffer()` `macro_add_key()`, `clear_macro(), `stop_macro()`
- `check_window()`, `check_buffer()`, `qe_kill_buffer()`, `qe_get_history()`
- `qe_register_charset()`, `find_charset()`
Add error message handlers:
- add `QEDisplay::dpy_error()` method
- add `qe_cfg_error()`, use for all expression parsing errors
- pass opaque pointer to `css_error()`
- add `qe_put_error()` and `qe_dpy_error()`
Add context argument:
- always pass a non-null window pointer to `do_refresh()`, `new_help_buffer()`
Rename functions:
- `find_resource_file` -> `qe_find_resource_file`
- `open_resource_file` -> `qe_open_resource_file`
- `input_methods_init` -> `qe_input_methods_init`
- `load_input_methods` -> `qe_load_input_methods`
- `unload_input_methods` -> `qe_unload_input_methods`
- `find_input_methods` -> `qe_find_input_methods`
- `register_input_method` -> `qe_register_input_method`
- `parse_command_line` -> `qe_parse_command_line`
- `eb_trace_bytes` -> `qe_trace_bytes`
- `eb_init` -> `qe_data_init`
- `eb_count_buffers` -> `qe_count_buffers`
- `eb_get_buffer_from_index` -> `qe_get_buffer_from_index`
- `init_all_modules` -> `qe_init_all_modules`
- `exit_all_modules` -> `qe_exit_all_modules`
- `load_all_modules` -> `qe_load_all_modules`
- `maybe_set_mark` -> `do_maybe_set_mark`
- `unget_key` -> `qe_unget_key`
- `minibuffer_init` -> `qe_minibuffer_init`
- `edit_display` -> `qe_display`
- `new_yank_buffer` -> `qe_new_yank_buffer`
- `new_shell_buffer` -> `qe_new_shell_buffer`
- `shell_find_mode` -> `qe_shell_find_mode`
- `save_selection` -> `qe_save_selection`
- `register_emulation_bindings` -> `qe_register_emulation_bindings`
- `macro_add_key` -> `qe_macro_add_key`
- `clear_macro` -> `qe_clear_macro`
- `stop_macro` -> `qe_stop_macro`
- `eb_format_message` -> `qe_format_message`
- `screen_init` -> `qe_screen_init`
- `charset_jis_init` -> `qe_charset_jis_init`
- `charset_more_init` -> `qe_charset_more_init`
- `check_window` -> `qe_check_window`
- `check_buffer` -> `qe_check_buffer`
- `eb_find_file` -> `qe_find_buffer_file`
- `eb_find` -> `qe_find_buffer_name`
- `eb_new` -> `qe_new_buffer`
- `eb_find_new` -> `qe_new_buffer` with `BC_REUSE`
- `eb_scratch` -> `qe_new_buffer` with `BC_REUSE | BC_CLEAR`
- `find_charset` -> `qe_find_charset`
Add asan, msan and ubsan targets
Fix `qe_encode64` buffer length computation.
Add `qe_new_shell_buffer` flags `SF_REUSE_BUFFER` and `SF_ERASE_BUFFER`
Bumped version to 6.3.3
fix redundant typedef
fix compilation errors
2024-12-01 23:34:00 +01:00
|
|
|
qe_register_mode(qs, &org_mode, MODEF_SYNTAX);
|
|
|
|
|
qe_register_commands(qs, &org_mode, org_commands, countof(org_commands));
|
2014-01-07 18:26:07 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qe_module_init(org_init);
|