Commit graph

68 commits

Author SHA1 Message Date
Charlie Gordon
dc4eb3efb6 man: ensure full manual page is formatted and uses hightlighting
- set `MAN_KEEP_FORMATTING=1` and `MANPAGER=cat` for the man
  command and handle overstriking in the terminal emulation.
- this approach works on macOS, linux, FreeBSD and OpenBSD
2026-05-17 16:12:36 +02:00
huwwa
cbeb5d4acd Shell: prevent man command from paging
- apply infinite-height prior to winsize initialization.
- use `LESS_LINES` environment variable.
- use `PAGER=less -F` to make less quit at the end of the man page
2026-05-17 12:49:56 +02:00
huwwa
053871bec7 Pager: verify existance of last buffer on abort 2026-05-17 00:03:01 +02:00
huwwa
34488a2ed4 Shell: use window width and height fields directly 2026-05-17 00:03:01 +02:00
huwwa
eefc007d60 Pager: add pager-abort command 2026-05-16 22:32:06 +02:00
huwwa
c654f504e5 Shell: refine target window selection logic
The behavior follows this priority order:

1. reuse an existing window already displaying the buffer,
2. if shell-command-other-window is not set, use the current
   window, otherwise
3. select the largest available non-active window.
4. split a new window if no sutiable window is found.
5. fall back to the current window if splitting fails.
2026-05-16 22:32:06 +02:00
huwwa
a927d093ab Shell: improve shell_close/shell_read_cb
- add check when process is signaled.
- put appropriate status message when non-interactive.
- follow output stream when non-interactive.
2026-05-16 22:32:06 +02:00
huwwa
ec1aee59a4 Shell: cosmetic changes
- add interactive shell process caption.
- rearrange lines.
2026-05-16 22:32:06 +02:00
Charlie Gordon
7f3b31d8d4 Shell: add optional shell modes
- `shell_buffer_read_only` controls if the shell buffer should become
  read-only and use pager-mode when not interactive
- `shell_mode_auto_interactive` controls if the shell interactive mode is
  switched to and from automatically based on cursor movement commands
- disable auto interactive if region is highlighted
- fix crash bug in qe_register_emulation_bindings for "emacs" emulation
2026-05-11 00:21:56 +02:00
huwwa
880aa115cd shell: sync interactive state between windows sharing the same shell buffer 2026-05-11 00:21:56 +02:00
huwwa
7d7a7d0fac shell: update toggle input status message 2026-05-11 00:21:56 +02:00
huwwa
2af3c40706 shell: split interactive and non-interactive shell commands 2026-05-11 00:21:56 +02:00
huwwa
5b87d2e4ff shell: manage interactive mode and readonly state
* decouple interactive mode from cursor position.
* clear readonly when entering interactive mode and
  restore when leaving it.
* simplify navigation logic by removing offset-based toggling.
* set pager mode on interactive shell exit.
2026-05-11 00:21:56 +02:00
huwwa
8a9c4412ed shell: check process termination before closing 2026-05-06 14:23:14 +02:00
huwwa
668a4be142 shell: avoid leaving stray processes when reusing a shell buffer
* check for active processes in shell buffers before reusing them,
  and prompt the user to kill the running process to avoid leaving
  it detached and unreachable.
2026-05-06 14:23:14 +02:00
huwwa
640ad15e4d shell: try to split window for shell commands 2026-05-06 14:23:14 +02:00
huwwa
db2bbc4c71 remove extra new line with caption
* `ctime` format ends with a new line.
2026-05-06 14:23:14 +02:00
huwwa
4d3e1e0810 shell: encapsulate error variables in a global ShellError structure 2026-05-06 14:23:14 +02:00
huwwa
b3f37b7b23 check for active process associated with the buffer before killing it
* killing a shell buffer while its process is still running can leave the
  process alive but no longer accessible.
2026-05-06 14:23:14 +02:00
huwwa
42c88b10ca default exit status to -1 if not launched 2026-05-06 14:23:14 +02:00
huwwa
aeb0767a3c fix: defer pty closure until buffer is fully drained
fixes a race condition where pty data was lost on process exit.
The pid callback now flags the exit status, while `shell_read_cb`
handles the final teardown. This prevents truncation for
high-throughput processes.
2026-05-06 14:23:14 +02:00
huwwa
adc72a8b0a set readonly flag for compilation buffer 2026-05-06 14:23:14 +02:00
huwwa
9502e20d52 fix: use appropriate buffer flag 2026-05-06 14:23:14 +02:00
Charlie Gordon
d2db97217c disable transient bindings on next-error and previous-error 2026-02-06 13:02:09 +01:00
huwwa
93539ead18 replace depricated getdtablesize with sysconf 2026-02-06 12:45:28 +01:00
Charlie Gordon
e4fb8c8428
Improve language colorizers (#54)
* fix detection of javascript partial comments in diff output
* colorize python annotations
* add simplistic yaml colorizer
* colorize .gitignore files
* improve shell buffer diff output colorization
2024-12-14 23:56:54 +01:00
Charlie Gordon
e0ba872d77
Improve error reporting (#50)
- rename `edit_new` as `qe_new_window`
- report error in `qe_new_buffer` and `qe_new_window` upon failure
- rename `qe_find_buffer_file` as `qe_find_buffer_filename`
- rename `read_charset` as `qe_parse_charset`
- reset yank buffer references in `eb_clear()`
- make `qe_init()` return error code and abort upon error
2024-12-08 19:43:26 +01:00
Charlie Gordon
f674419e75
Fix put_status/put_error behavior (#47)
* Fix `put_status`/`put_error` behavior

- use `put_error` instead of `put_status` for command errors
- prevent status message output to console during initialization
- use `put_error` for side effects in command errors
- add `&` prefix in status messages to force screen flush
- flush screen in `qe_display()`, remove redundant calls to `dpy_flush`
- fix gcc compilation errors and warnings
- remove most references to `global_screen`
- free font cache before closing the screen
- prevent mouse handling upon focus detection

* drop CI on macos-12
2024-12-03 22:52:55 +01:00
Charlie Gordon
e3c5bfd457
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
Charlie Gordon
ab86598e29 Automate modifyOtherKeys, mouse and clipboard support detection
- intialize `tty_mk`, `tty_mouse` and `tty_clipboard` to `-1` for automatic
- command line options force setting
- otherwise, configure support from environment variables (for now)
2024-10-11 09:14:16 +02:00
Charlie Gordon
9815df4c68 Fix shell buffer CSI parameter parsing 2024-09-25 01:02:14 +02:00
Charlie Gordon
288eeb450e Improve modern terminal support
- improve ANSI tty and shell buffer escape sequence parser
- detect backspace/delete input setting from termios structure
- renumber special keys, remove redundant definitions
- handle shift state modifiers generically
- support tty `modifyOtherKeys` key encoding
- support tty `CSI u` key encoding
- simplify x11 key handling
- simplify haiku key handling (untested)
- bump VERSION to 6.3.1
- rename `insert-color` as `read-color`, insert code on `C-u C-c #`
- simplify string to key conversions
- improve CSI and OSC sequence support (ESC ] ... ^G or ST)
- `do_toggle_control_h()` should just toggle `ts->term_flags & KBS_CONTROL_H`
2024-09-25 01:02:14 +02:00
Charlie Gordon
9e10de752e Improve color selection and completion
- add `set-style-color(string style, string color)` command
- display color and style samples in completion window
- display style names in `what-cursor-position` on `C-x =`
- remove duplicates in completion lists
2024-09-07 18:40:44 +02:00
oguillaumin
d2aa2a8c13 colorize grep -[ABC] output in shell buffers 2024-08-31 13:49:00 +02:00
oguillaumin
329204ab58 improve C comment colorization of diff output in shell buffer 2024-08-31 13:49:00 +02:00
oguillaumin
1d3cabeaa2 Improve indentation commands
* add `find_indent` and `make_indent` ancillary functions
* add `untabulate` on `S-TAB` to remove one indentation level
* rename `do_tab` as `do_tabulate` for consistency
* `tabulate` indents the region one level if visible
* add `indent-rigidly` commands: indent block interactively
2024-08-31 13:49:00 +02:00
oguillaumin
da0ce59b03 fix shell mode colorisation 2024-08-31 13:49:00 +02:00
Charlie Gordon
7b803ace0e Improve syntax coloring APIs
* pass const `char32_t` array and `QETermStyle` array to `ColorizeFunc`
* add `cp_colorize_line()` wrapper to call colorizer function on null
  terminated buffer.
* remove unused `EditBuffer` colorize fields
* remove `EditState` field `colorize_func`: rely on `colorize_mode` only
* no longer combine style into codepoint buffer.
* remove `STYLE_BITS`, `STYLE_SHIFT`, `CHAR_MASK`
* rename `set_colorize_func` as `set_colorize_mode`
* rename `SET_COLOR` and `SET_COLOR1` as `SET_STYLE` and `SET_STYLE1`
* add documentation for buffer API functions
2024-07-28 00:00:03 +02:00
Charlie Gordon
e0d9a641d3
Add repeat-mode (#34)
- add `repeat` command on `C-x z`
- add `repeat-mode`, always enabled
- cycle all matching tags in current file on `goto-tag` and `find-tag`
- set up `repeat-mode` for these commands:
  - `undo` on `C-x u` (`u` repeats `undo`, `r` performs `redo`)
  - `undo` on `C-x r` (`r` repeats `redo`, `u` performs `undo`)
  - `find-window-left`, `find-window-right`, `find-window-up`, `find-window-dow`
    repeat navigation on `up`, `down`, `left`, `right`
  - `next-error`, `previous-error`: `M-n` and `M-p` repeat in corresponding direction
  - `next-buffer`, `previous-buffer: repeat buffers nagivation with `left` and `right`
  - `enlarge-window` / `shrink-window`: repeat resizing on `^`, `v`, `{`, `}`
     and cursor movement keys
  - `goto-tag` on `C-x ,` goto next tag with `,` and `.`
  - `call-last-kbd-macro` on `C-x e`: repeat macro on `e`
- add `eb_count_buffers` and `eb_get_buffer_from_index` for safe buffer navigation
- add transient bindings, known as repeat maps in GNU emacs
- pass `KeyDef **lp` (aka key maps) instead of mode for binding commands
- replace `do_next_buffer` and `do_prevous_buffer` with repeatable command
  `do_buffer_navigation`
- fix `bufed_select` crash bug when selecting buffer from a regular window
2024-05-25 23:37:05 +02:00
Charlie Gordon
a388a95305
Pass QEmacsState pointer to all module_init and module_exit functions (#24) 2024-05-19 19:15:08 +02:00
Charlie Gordon
eb46f4bd87 Improve shell-mode colorizer
- dump colorize_states in describe-window
- improve shell output parser to colorize code in shell output:
  * recognize patch output (diff -u)
  * recognize compiler errors
  * recognize some commands: cat, head, tail
2024-02-10 20:47:53 +01:00
oguillaumin
f36144d6a8 Change license to MIT
* bumped VERSION to 6.0.0
2023-03-05 02:04:02 +01:00
Charlie Gordon
d0f7b7a904 Various improvements for consistency
* add -Wno-packed compiler option
* add CONFIG_REGEX flag, undefined for tiny build
* disable regex commands in tiny build
* add documentation for some search commands and APIs
* reorder search tags for readability
* add isearch_yank_char
* use emacs names for:
  isearch-repeat-backward, isearch-repeat-forward,
  isearch-ring-advance, isearch-ring-retreat,
  isearch-yank-word-or-char
* add occur alias for list-matching-lines
* add char32_to_utf8()
* restored some macros in cutils.h:
  likely(x), unlikely(x), __maybe_unused, BOOL, FALSE, TRUE
* remove max(), min(), maxp(), minp(), clampp()
* add typed arithmetic functions:
   min_int(), max_int(), clamp_int(), min3_int(), max3_int()
   min_offset(), max_offset(), clamp_offset()
* use typed functions everywhere

* bump version to 5.4.1d
2022-11-21 00:20:18 +01:00
Charlie Gordon
6880277ec0 Improvements in search functions
* add search modes:
  copy-matching-lines, kill-matching-lines, list-matching-lines
  - add enum for search modes

* add search flag support in all search functions:
    search_forward, search_backward, count-matches, delete-matching-lines,
    delete-non-matching-lines, copy-matching-lines, kill-matching-lines,
    list-matching-lines, query-replace, replace-string
  - highlight matches during search string input
  - add search flag toggle functions in minibuffer_edit
    same code and bindings as for incremental search
  - add handlers in CompletionDef for minibuffer_edit session start and end
  - use generic search tag system to store flags in search string

* misc improvements and bug fixes:
  - test and set append-next-kill on kill-region
  - split `do_copy_region` from `do_kill_region`
  - remove argument in `do_kill_region` for `kill-region`
  - change immediate string argument code letter from 'S' to '@'
  - exit popup with do_popup_exit() in do_keyboard_quit
    remove popup_mode binding
  - add ESiii and ESsii command calling conventions
  - pass key and argval to:
    minibuffer_complete, do_minibuffer_complete_space,
    do_minibuffer_electric_key

* add default bindings:
    `next-error` on `M-g n`, `M-g M-n`
    `previous-error` on `M-g p`, `M-g M-p`
    `goto-line` on `M-g g`, `M-g M-g`, `C-x g`
    `goto-char` on `M-g c`

* bump version to 5.4.1a
2022-11-06 12:08:19 +01:00
Charlie Gordon
7e70e611b6 Use char32_t for all code point variables and arrays
- char32_t is defined in cutils.h but may conflict with <uchar.h>
- all qe_isxxx functions take a char32_t
- add etf8x encoding for full range of char32_t type
- add utf8_decode_strict()
- add ustr_match_keyword()
- utf8_encode() / utf8_decode() handle up to 32 bits
- improve detect_charset():
  - detect utf8 and utf8x
  - avoid failure on partial utf8 sequence at end of buffer
  - detect overlong utf8 sequences
- fix display bugs for code points beyond MAX_UNICODE_DISPLAY
- simplify do_compare_windows(), avoid magic char values.
- rename functions:
    eb_encode_uchar -> eb_encode_char32
    eb_insert_uchar -> eb_insert_char32
    eb_insert_uchars -> eb_insert_char32_n
    eb_match_uchar -> eb_match_char32
    eb_delete_uchar -> eb_delete_char32
    eb_replace_uchar -> eb_replace_char32
    utf8_to_unicode -> utf8_to_char32
- use char32_t for all variables and arrays holding code-points
- fix some language syntax parsers.
- fix detect_eol_type_32bit(), used uint16_t instead of uint32_t
- bump VERSION to 5.4.0
2022-10-29 19:43:38 +02:00
Charlie Gordon
0be702e51b use UTF-8 in uppercase in comments 2022-10-04 14:53:25 +02:00
Charlie Gordon
490ebfbb0b Fix gcc warning. Fixes issue #9 2022-09-29 12:19:58 +02:00
Charlie Gordon
1beb610d76 Update glyph width methodology
- rename unicode_tty_glyph_width() as qe_wcwidth()
- compute tables for qe_wcwidth() with tools/unicode_gen.c
  from the latest Unicode version
- add qe_wcwidth_variant() to determine if terminal may use
  incorrect width for a given glyph.
- reposition TTY cursor for glyphs with ambiguous width
- remove unicode_width.h
- add wcwidth.h and wcwidth.c generated by tools/unicode_gen.c
- update tools/unicode_gen.c and tools/unitable.c
- determine Unicode version support at start time
  displayed by describe-screen command
- display code point width and variant in what-cursor-position command (C-x ?)
- bumped VERSION to 5.3.4x
2022-09-27 22:30:05 +02:00
Charlie Gordon
d1fb4dde64 Add macros for block comparison, copy and move
After spending a few hours debugging a stupid memcpy size error, I
decided to use a typed version of memcpy, memcmp and memmove wherever
the array type size is greater than 1.

- add blockcmp(p1, p2, n), blockcpy(p1, p2, n), blockmove(p1, p2, n)
  for operation on typed arrays
- add max_uint() and min_uint()
- bumped VERSION to 5.3.4w
2022-09-27 09:32:41 +02:00
Charlie Gordon
bd50376780 Various improvements
- add charset.h
- add tools/unitable.c to compute unicode_width.h
- add tools/unicode_gen.c to compute more unicode tables
- use Unicode 15.0.0
- add rules to compute width tables from Unicode tables and TTY
- move basic definitions from util.h to cutils.h
- use CONFIG_SESSION for session support (undefined if CONFIG_TINY)
- define CompleteFunc and CT_xxx flags for completion functions
- pass CompleteFunc to xxx_complete() functions
  this allows more generic implemetation, without including qe.h
- rename fill_border() as fill_window_slack() for readability
- add QELEVEL environment variable to detect recursive invocation
- use stricter parser for load_ligatures()
- bump VERSION to 5.3.4u
2022-09-19 15:16:59 +02:00