aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vterm-module.h5
-rw-r--r--vterm.el270
2 files changed, 171 insertions, 104 deletions
diff --git a/vterm-module.h b/vterm-module.h
index 0aa18ae..59beba0 100644
--- a/vterm-module.h
+++ b/vterm-module.h
@@ -20,7 +20,8 @@ int plugin_is_GPL_compatible;
typedef struct LineInfo {
char *directory; /* working directory */
- int prompt_col; /* end column of the prompt,if current line contains prompt */
+ int prompt_col; /* end column of the prompt, if the current line contains the
+ * prompt */
} LineInfo;
typedef struct ScrollbackLine {
@@ -74,7 +75,7 @@ typedef struct Term {
char *elisp_code;
bool elisp_code_changed;
- /* the size of dirs almost = window height,value = directory of that line */
+ /* the size of dirs almost = window height, value = directory of that line */
LineInfo **lines;
int lines_len;
diff --git a/vterm.el b/vterm.el
index 5ce0b84..84fe4cf 100644
--- a/vterm.el
+++ b/vterm.el
@@ -1,6 +1,6 @@
;;; vterm.el --- This package implements a terminal via libvterm -*- lexical-binding: t; -*-
-;; Copyright (C) 2017-2019 by Lukas Fürmetz
+;; Copyright (C) 2017-2020 by Lukas Fürmetz & Contributors
;;
;; Author: Lukas Fürmetz <fuermetz@mailbox.org>
;; Version: 0.0.1
@@ -22,7 +22,7 @@
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
@@ -43,8 +43,8 @@
;;; Code:
(unless module-file-suffix
- (error "VTerm needs module support. Please compile your Emacs
- with the --with-modules option!"))
+ (error "VTerm needs module support. Please compile Emacs with
+ the --with-modules option!"))
;; Compilation of the module
@@ -54,11 +54,11 @@
Currently, vterm defines the following flags (in addition to the
ones already available in CMake):
-`USE_SYSTEM_LIBVTERM'. Set it to `yes' to use the version of
+`USE_SYSTEM_LIBVTERM'. Set it to `yes' to use the version of
libvterm installed on your system.
This string is given verbatim to CMake, so it has to have the
-correct syntax. An example of meaningful value for this variable
+correct syntax. An example of meaningful value for this variable
is `-DUSE_SYSTEM_LIBVTERM=yes'."
:type 'string
:group 'vterm)
@@ -72,7 +72,7 @@ CMake is needed to build vterm, here we check that we can find
the executable."
(unless (executable-find "cmake")
- (error "Vterm needs CMake to be compiled. Please, install CMake"))
+ (error "Vterm needs CMake to be compiled. Please, install CMake"))
t)
;;;###autoload
@@ -104,8 +104,21 @@ the executable."
(vterm-module-compile)
(require 'vterm-module))
+;; Silence compiler warnings by informing it of what functions are defined
(declare-function display-line-numbers-update-width "display-line-numbers")
+;; Generate this list with:
+;; awk -F\" '/bind_function*/ {print "(declare-function", $2, "\"vterm-module\")"}' vterm-module.c
+(declare-function vterm--new "vterm-module")
+(declare-function vterm--update "vterm-module")
+(declare-function vterm--redraw "vterm-module")
+(declare-function vterm--write-input "vterm-module")
+(declare-function vterm--set-size "vterm-module")
+(declare-function vterm--set-pty-name "vterm-module")
+(declare-function vterm--get-pwd-raw "vterm-module")
+(declare-function vterm--reset-point "vterm-module")
+(declare-function vterm--get-icrnl "vterm-module")
+
(require 'subr-x)
(require 'cl-lib)
(require 'term)
@@ -119,7 +132,11 @@ the executable."
:group 'vterm)
(defcustom vterm-max-scrollback 1000
- "Maximum 'scrollback' value."
+ "Maximum 'scrollback' value.
+
+The maximum allowed is 100000. This value can modified by
+changing the SB_MAX variable in vterm-module.h and recompiling
+the module."
:type 'number
:group 'vterm)
@@ -129,24 +146,37 @@ the executable."
:group 'vterm)
(defcustom vterm-kill-buffer-on-exit nil
- "Kill vterm buffer when the attached process is terminated."
- :type '(radio (const :tag "Kill buffer" t)
- (const :tag "Do not kill buffer" nil))
+ "Should a vterm buffer be killed when the attached process is terminated?
+
+If `vterm-kill-buffer-on-exit' is set to t, when the process
+associated to a vterm buffer quits, the buffer is killed.
+When nil, the buffer will still be available as if it were in
+`fundamental-mode'."
+ :type 'boolean
:group 'vterm)
(defcustom vterm-clear-scrollback nil
- "If not nil `C-l' will clear both screen and scrollback.
-else it will only clean screen."
+ "Should `vterm-clear' clear the scrollback too?.
+
+When nil, `vterm-clear' clears both screen and scrollback,
+otherwise it clears only the screen.
+
+Calling `vterm-clear' with a prefix argument does the opposite
+than the default behavior."
:type 'number
:group 'vterm)
(defcustom vterm-keymap-exceptions
-'("C-c" "C-x" "C-u" "C-g" "C-h" "C-l" "M-x" "M-o" "C-v" "M-v" "C-y" "M-y")
- "Exceptions for vterm-keymap.
+ '("C-c" "C-x" "C-u" "C-g" "C-h" "C-l" "M-x" "M-o" "C-v" "M-v" "C-y" "M-y")
+ "Exceptions for `vterm-keymap'.
If you use a keybinding with a prefix-key, add that prefix-key to
-this list. Note that after doing so that prefix-key cannot be sent
-to the terminal anymore."
+this list. Note that after doing so that prefix-key cannot be sent
+to the terminal anymore.
+
+The mapping is done by the macro `vterm-bind-key', and the
+function `vterm--exclude-keys' removes the keybindings defined in
+`vterm-keymap-exceptions'."
:type '(repeat string)
:set (lambda (sym val)
(set sym val)
@@ -172,7 +202,7 @@ Note that this hook will not work if another package like
(defcustom vterm-set-title-functions nil
"Shell set title hook.
-those functions are called one by one, with 1 arguments.
+These functions are called one by one, with one argument.
`vterm-set-title-functions' should be a symbol, a hook variable.
The value of HOOK may be nil, a function, or a list of functions.
For example
@@ -182,7 +212,7 @@ For example
'vterm--rename-buffer-as-title)
See http://tldp.org/HOWTO/Xterm-Title-4.html about how to set
-terminal title for different shell"
+terminal title for different shells."
:type 'hook
:group 'vterm)
@@ -194,7 +224,7 @@ terminal title for different shell"
(defcustom vterm-eval-cmds '(("find-file" find-file)
("message" message)
("vterm-clear-scrollback" vterm-clear-scrollback))
- "Map of commands to functions. To be used by vterm--eval.
+ "Map of commands to functions. To be used by `vterm--eval'.
Avoid using EVAL on input arguments, as it could allow a third
party to commandeer your editor."
@@ -212,7 +242,10 @@ party to commandeer your editor."
:group 'vterm)
(defcustom vterm-disable-bold-font nil
- "Disable bold fonts or not."
+ "Disable bold fonts or not.
+
+When `vterm-disable-bold-font' is set to t, bold fonts are
+rendered as normal ones."
:type 'boolean
:group 'vterm)
@@ -325,8 +358,10 @@ Only background is used."
(defvar vterm-timer-delay 0.1
"Delay for refreshing the buffer after receiving updates from libvterm.
+
Improves performance when receiving large bursts of data.
-If nil, never delay")
+If nil, never delay.
+The units are seconds.")
(define-derived-mode vterm-mode fundamental-mode "VTerm"
"Major mode for vterm buffer."
@@ -369,18 +404,21 @@ If nil, never delay")
:coding 'no-conversion
:connection-type 'pty
:filter #'vterm--filter
- ;; Sentinel needed if there are exit functions or if vterm-kill-buffer-on-exit
- ;; is set to t. In this latter case, vterm--sentinel will kill the buffer
+ ;; The sentinel is needed if there are exit functions or if
+ ;; vterm-kill-buffer-on-exit is set to t. In this latter case,
+ ;; vterm--sentinel will kill the buffer
:sentinel (when (or vterm-exit-functions
vterm-kill-buffer-on-exit)
#'vterm--sentinel))))
(vterm--set-pty-name vterm--term (process-tty-name vterm--process))
(process-put vterm--process 'adjust-window-size-function
#'vterm--window-adjust-process-window-size)
+ ;; Support to compilation-shell-minor-mode
+ ;; Is this necessary? See vterm--compilation-setup
(setq next-error-function 'vterm-next-error-function))
(defun vterm--compilation-setup ()
- "Function to setup `compilation-shell-minor-mode' for vterm.
+ "Function to enable the option `compilation-shell-minor-mode' for vterm.
`'compilation-shell-minor-mode' would change the value of local
variable `next-error-function', so we should call this function in
`compilation-shell-minor-mode-hook'."
@@ -392,7 +430,11 @@ variable `next-error-function', so we should call this function in
;;;###autoload
(defun vterm-next-error-function (n &optional reset)
"Advance to the next error message and visit the file where the error was.
-This is the value of `next-error-function' in Compilation buffers."
+This is the value of `next-error-function' in Compilation
+buffers. Prefix arg N says how many error messages to move
+forwards (or backwards, if negative).
+
+Optional argument RESET clears all the errors."
(interactive "p")
(let* ((pt (point))
(default-directory default-directory)
@@ -402,13 +444,15 @@ This is the value of `next-error-function' in Compilation buffers."
(goto-char pt)
(compilation-next-error-function n reset)))
-
+;; We have many functions defined by vterm-define-key. Later, we will bind some
+;; of the functions. If the following is not evaluated during compilation, the compiler
+;; will complain that some functions are not defined (eg, vterm-send-C-c)
(eval-and-compile
(defmacro vterm-define-key (key)
- "Define an command sending M-[a-z] or C-[a-z] to vterm."
+ "Define a command that sends KEY with modifiers C and M to vterm."
(declare (indent defun)
(doc-string 3))
- `(defun ,(intern(format "vterm-send-%s" key))()
+ `(defun ,(intern (format "vterm-send-%s" key))()
,(format "Sends %s to the libvterm." key)
(interactive)
(vterm-send-key ,(char-to-string (get-byte (1- (length key)) key)) nil
@@ -425,6 +469,9 @@ This is the value of `next-error-function' in Compilation buffers."
;; Function keys and most of C- and M- bindings
(defun vterm--exclude-keys (exceptions)
+ "Remove EXCEPTIONS from the keys bound by `vterm-bind-keys'.
+
+Exceptions are defined by `vterm-keymap-exceptions'."
(mapc (lambda (key)
(define-key vterm-mode-map (kbd key) nil))
exceptions)
@@ -491,8 +538,7 @@ This is the value of `next-error-function' in Compilation buffers."
(define-key vterm-mode-map (kbd "C-c C-t") #'vterm-copy-mode)
-(defvar vterm-copy-mode-map (make-sparse-keymap)
- "Minor mode map for `vterm-copy-mode'.")
+(defvar vterm-copy-mode-map (make-sparse-keymap))
(define-key vterm-copy-mode-map (kbd "C-c C-t") #'vterm-copy-mode)
(define-key vterm-copy-mode-map [return] #'vterm-copy-mode-done)
(define-key vterm-copy-mode-map (kbd "RET") #'vterm-copy-mode-done)
@@ -504,7 +550,12 @@ This is the value of `next-error-function' in Compilation buffers."
(define-minor-mode vterm-copy-mode
- "Toggle vterm copy mode."
+ "Toggle `vterm-copy-mode'.
+
+When `vterm-copy-mode' is enabled, the terminal will not display
+additional output received from the underlying process and will
+behave similarly to buffer in `fundamental-mode'. This mode is
+typically used to copy text from vterm buffers."
:group 'vterm
:lighter " VTermCopy"
:keymap vterm-copy-mode-map
@@ -522,9 +573,9 @@ This is the value of `next-error-function' in Compilation buffers."
If a region is defined then that region is killed, with no region then
current line is killed from start to end.
-The option `vterm-copy-exclude-prompt` controls if the prompt
-should be included in a line copy. Using the universal prefix
-will invert `vterm-copy-exclude-prompt` for that call."
+The option `vterm-copy-exclude-prompt' controls if the prompt
+should be included in a line copy. Using the universal prefix ARG
+will invert `vterm-copy-exclude-prompt' for that call."
(interactive "P")
(unless vterm-copy-mode
(user-error "This command is effective only in vterm-copy-mode"))
@@ -533,16 +584,15 @@ will invert `vterm-copy-exclude-prompt` for that call."
;; Are we excluding the prompt?
(if (or (and vterm-copy-exclude-prompt (not arg))
(and (not vterm-copy-exclude-prompt) arg))
- (goto-char (max (vterm--get-prompt-point)
- (vterm--get-beginning-of-line))))
+ (goto-char (max (vterm--get-prompt-point)
+ (vterm--get-beginning-of-line))))
(set-mark (point))
(goto-char (vterm--get-end-of-line)))
-
(kill-ring-save (region-beginning) (region-end))
(vterm-copy-mode -1))
(defun vterm--self-insert ()
- "Sends invoking key to libvterm."
+ "Send invoking key to libvterm."
(interactive)
(when vterm--term
(let* ((modifiers (event-modifiers last-input-event))
@@ -563,7 +613,7 @@ will invert `vterm-copy-exclude-prompt` for that call."
(setq vterm--redraw-immididately t))))
(defun vterm-send (key)
- "Sends KEY to libvterm. KEY can be anything ‘kbd’ understands."
+ "Sends KEY to libvterm. KEY can be anything `kbd' understands."
(let* ((event (listify-key-sequence (kbd key)))
(modifiers (event-modifiers event))
(base (event-basic-type event)))
@@ -583,7 +633,7 @@ will invert `vterm-copy-exclude-prompt` for that call."
(vterm-send-key "<stop>"))
(defun vterm-send-return ()
- "Sends C-m to the libvterm."
+ "Send `C-m' to the libvterm."
(interactive)
(when vterm--term
(if (vterm--get-icrnl vterm--term)
@@ -591,81 +641,88 @@ will invert `vterm-copy-exclude-prompt` for that call."
(process-send-string vterm--process "\C-m"))))
(defun vterm-send-tab ()
- "Sends `<tab>' to the libvterm."
+ "Send `<tab>' to the libvterm."
(interactive)
(vterm-send-key "<tab>"))
(defun vterm-send-space ()
- "Sends `<space>' to the libvterm."
+ "Send `<space>' to the libvterm."
(interactive)
(vterm-send-key " "))
(defun vterm-send-backspace ()
- "Sends `<backspace>' to the libvterm."
+ "Send `<backspace>' to the libvterm."
(interactive)
(vterm-send-key "<backspace>"))
(defun vterm-send-delete ()
- "Sends `<delete>' to the libvterm."
+ "Send `<delete>' to the libvterm."
(interactive)
(vterm-send-key "<delete>"))
(defun vterm-send-meta-backspace ()
- "Sends `M-<backspace>' to the libvterm."
+ "Send `M-<backspace>' to the libvterm."
(interactive)
(vterm-send-key "<backspace>" nil t))
(defun vterm-send-up ()
- "Sends `<up>' to the libvterm."
+ "Send `<up>' to the libvterm."
(interactive)
(vterm-send-key "<up>"))
(defun vterm-send-down ()
- "Sends `<down>' to the libvterm."
+ "Send `<down>' to the libvterm."
(interactive)
(vterm-send-key "<down>"))
-(defun vterm-send-left()
- "Sends `<left>' to the libvterm."
+(defun vterm-send-left ()
+ "Send `<left>' to the libvterm."
(interactive)
(vterm-send-key "<left>"))
-(defun vterm-send-right()
- "Sends `<right>' to the libvterm."
+(defun vterm-send-right ()
+ "Send `<right>' to the libvterm."
(interactive)
(vterm-send-key "<right>"))
-(defun vterm-send-prior()
- "Sends `<prior>' to the libvterm."
+(defun vterm-send-prior ()
+ "Send `<prior>' to the libvterm."
(interactive)
(vterm-send-key "<prior>"))
-(defun vterm-send-next()
- "Sends `<next>' to the libvterm."
+(defun vterm-send-next ()
+ "Send `<next>' to the libvterm."
(interactive)
(vterm-send-key "<next>"))
-(defun vterm-send-meta-dot()
- "Sends `M-.' to the libvterm."
+(defun vterm-send-meta-dot ()
+ "Send `M-.' to the libvterm."
(interactive)
(vterm-send-key "." nil t))
-(defun vterm-send-meta-comma()
- "Sends `M-,' to the libvterm."
+(defun vterm-send-meta-comma ()
+ "Send `M-,' to the libvterm."
(interactive)
(vterm-send-key "," nil t))
(defun vterm-send-ctrl-slash ()
+ "Send `C-\' to the libvterm."
(interactive)
(vterm-send-key "\\" nil nil t))
(defun vterm-clear-scrollback ()
- "Sends `<clear-scrollback>' to the libvterm."
+ "Send `<clear-scrollback>' to the libvterm."
(interactive)
(vterm-send-key "<clear_scrollback>"))
(defun vterm-clear (&optional arg)
- "Sends `<clear-scrollback>' to the libvterm."
+ "Send `<clear>' to the libvterm.
+
+`vterm-clear-scrollback' determines whether
+`vterm-clear' should also clear the scrollback or not.
+
+This behavior can be altered by calling `vterm-clear' with a
+prefix argument ARG or with \\[universal-argument]."
(interactive "P")
(if (or
(and vterm-clear-scrollback (not arg))
@@ -674,34 +731,38 @@ will invert `vterm-copy-exclude-prompt` for that call."
(vterm-send-C-l))
(defun vterm-undo ()
- "Sends `C-_' to the libvterm."
+ "Send `C-_' to the libvterm."
(interactive)
(vterm-send-key "_" nil nil t))
(defun vterm-yank (&optional arg)
- "Implementation of `yank' (paste) in vterm."
+ "Yank (paste) text in vterm.
+
+Argument ARG is passed to `yank'."
(interactive "P")
(let ((inhibit-read-only t))
(cl-letf (((symbol-function 'insert-for-yank)
- #'(lambda(str) (vterm-send-string str t))))
+ #'(lambda (str) (vterm-send-string str t))))
(yank arg))))
(defun vterm-yank-primary ()
- "Implementation of `mouse-yank-primary' in vterm."
+ "Yank text from the primary selection in vterm."
(interactive)
(let ((inhibit-read-only t)
(primary (gui-get-primary-selection)))
(cl-letf (((symbol-function 'insert-for-yank)
- #'(lambda(str) (vterm-send-string str t))))
+ #'(lambda (str) (vterm-send-string str t))))
(insert-for-yank primary))))
-(defun vterm-yank-pop(&optional arg)
- "Implementation of `yank-pop' in vterm."
+(defun vterm-yank-pop (&optional arg)
+ "Replaced text just yanked with the next entry in the kill ring.
+
+Argument ARG is passed to `yank'"
(interactive "p")
(let ((inhibit-read-only t)
- (yank-undo-function #'(lambda(_start _end) (vterm-undo))))
+ (yank-undo-function #'(lambda (_start _end) (vterm-undo))))
(cl-letf (((symbol-function 'insert-for-yank)
- #'(lambda(str) (vterm-send-string str t))))
+ #'(lambda (str) (vterm-send-string str t))))
(yank-pop arg))))
(defun vterm-send-string (string &optional paste-p)
@@ -716,7 +777,7 @@ Optional argument PASTE-P paste-p."
(vterm--update vterm--term "<end_paste>" nil nil nil)))
(setq vterm--redraw-immididately t))
-(defun vterm--invalidate()
+(defun vterm--invalidate ()
"The terminal buffer is invalidated, the buffer needs redrawing."
(if (and (not vterm--redraw-immididately)
vterm-timer-delay)
@@ -728,16 +789,17 @@ Optional argument PASTE-P paste-p."
(setq vterm--redraw-immididately nil)))
(defun vterm-check-proc (&optional buffer)
- "True if there is a process associated w/buffer BUFFER, and it
-is alive. BUFFER can be either a buffer or the name of one."
+ "Check if there is a running process associated to the vterm buffer BUFFER.
+
+BUFFER can be either a buffer or the name of one."
(let* ((buffer (get-buffer (or buffer (current-buffer))))
(proc (get-buffer-process buffer)))
(and proc
(memq (process-status proc) '(run stop open listen connect))
(buffer-local-value 'vterm--term buffer))))
-(defun vterm--delayed-redraw(buffer)
- "Redraw the terminal buffer .
+(defun vterm--delayed-redraw (buffer)
+ "Redraw the terminal buffer.
Argument BUFFER the terminal buffer."
(when (buffer-live-p buffer)
(with-current-buffer buffer
@@ -746,6 +808,8 @@ Argument BUFFER the terminal buffer."
(windows (get-buffer-window-list)))
(setq vterm--redraw-timer nil)
(when vterm--term
+ ;; Check is `display-line-numbers' is being used, in that case, update
+ ;; the width
(when (and (bound-and-true-p display-line-numbers)
(require 'display-line-numbers nil 'noerror)
(get-buffer-window buffer t)
@@ -760,8 +824,8 @@ Argument BUFFER the terminal buffer."
(defun vterm (&optional buffer-name)
"Create a new vterm.
-If called with an argument ARG, the name of the new buffer will
-be set to ARG, otherwise it will be `vterm'"
+If called with an argument BUFFER-NAME, the name of the new buffer will
+be set to BUFFER-NAME, otherwise it will be `vterm'"
(interactive)
(let ((buffer (generate-new-buffer (or buffer-name "vterm"))))
(with-current-buffer buffer
@@ -772,8 +836,8 @@ be set to ARG, otherwise it will be `vterm'"
(defun vterm-other-window (&optional buffer-name)
"Create a new vterm in another window.
-If called with an argument ARG, the name of the new buffer will
-be set to ARG, otherwise it will be `vterm'"
+If called with an argument BUFFER-NAME, the name of the new buffer will
+be set to BUFFER-NAME, otherwise it will be `vterm'"
(interactive)
(let ((buffer (generate-new-buffer (or buffer-name "vterm"))))
(with-current-buffer buffer
@@ -781,18 +845,18 @@ be set to ARG, otherwise it will be `vterm'"
(pop-to-buffer buffer)))
(defun vterm--flush-output (output)
- "Sends the virtual terminal's OUTPUT to the shell."
+ "Send the virtual terminal's OUTPUT to the shell."
(process-send-string vterm--process output))
(defun vterm--filter (process input)
- "I/O Event. Feeds PROCESS's INPUT to the virtual terminal.
+ "I/O Event. Feeds PROCESS's INPUT to the virtual terminal.
Then triggers a redraw from the module."
(let ((inhibit-redisplay t)
(inhibit-read-only t)
(buf (process-buffer process)))
(when (buffer-live-p buf)
- (with-current-buffer buf
+ (with-current-buffer buf
(vterm--write-input vterm--term input)
(vterm--update vterm--term)))))
@@ -804,16 +868,15 @@ Argument EVENT process event."
(if (buffer-live-p buf) buf nil)
event)
(if (and vterm-kill-buffer-on-exit (buffer-live-p buf))
- (kill-buffer buf))
- ))
+ (kill-buffer buf))))
(defun vterm--text-scale-mode (&optional _argv)
- "fix `line-number' height for scaled text"
+ "Fix `line-number' height for scaled text."
(and text-scale-mode
(equal major-mode 'vterm-mode)
(boundp 'display-line-numbers)
(let ((height (expt text-scale-mode-step
- text-scale-mode-amount)))
+ text-scale-mode-amount)))
(when vterm--linenum-remapping
(face-remap-remove-relative vterm--linenum-remapping))
(setq vterm--linenum-remapping
@@ -822,9 +885,10 @@ Argument EVENT process event."
(advice-add #'text-scale-mode :after #'vterm--text-scale-mode)
-
(defun vterm--window-adjust-process-window-size (process windows)
- "Adjust process window size considering the width of line number."
+ "Adjust width of window WINDOWS associated to process PROCESS.
+
+`vterm-min-window-width' determines the minimum width allowed."
(let* ((size (funcall window-adjust-process-window-size-function
process windows))
(width (car size))
@@ -858,7 +922,7 @@ the whole line including its terminating newline"
(looking-at "\n"))
(delete-char 1)))))
-(defun vterm--goto-line(n)
+(defun vterm--goto-line (n)
"Go to line N and return true on success.
If N is negative backward-line from end of buffer."
(cond
@@ -905,7 +969,7 @@ If N is negative backward-line from end of buffer."
(when raw-pwd
(vterm--get-directory raw-pwd))))
-(defun vterm--get-color(index)
+(defun vterm--get-color (index)
"Get color by index from `vterm-color-palette'.
Argument INDEX index of the terminal color.
Special values for INDEX are:
@@ -913,14 +977,14 @@ Special values for INDEX are:
-2 for default background.
-11 foreground for cells with underline attribute, foreground of
the `vterm-color-underline' face is used in this case.
--12 background for cells with inverse-video attribute, background
+-12 background for cells with inverse video attribute, background
of the `vterm-color-inverse-video' face is used in this case."
(cond
- ((and (>= index 0)(< index 8))
+ ((and (>= index 0) (< index 8))
(face-foreground
(elt vterm-color-palette index)
nil 'default))
- ((and (>= index 8 )(< index 16))
+ ((and (>= index 8 ) (< index 16))
(face-background
(elt vterm-color-palette (% index 8))
nil 'default))
@@ -933,8 +997,8 @@ of the `vterm-color-inverse-video' face is used in this case."
(t ;-2 background
(face-background 'vterm-color-default nil 'default))))
-(defun vterm--eval(str)
- "Parse STR for command and arguments and call command defined in vterm-eval-cmds.
+(defun vterm--eval (str)
+ "Check if string STR is `vterm-eval-cmds' and execute command.
All passed in arguments are strings and forwarded as string to
the called functions."
@@ -948,7 +1012,7 @@ the called functions."
(defun vterm--prompt-tracking-enabled-p ()
- "Check whether feature of tracking the prompt is enabled or not.
+ "Return t if tracking the prompt is enabled.
Prompt tracking need shell side configurations.
@@ -1012,7 +1076,7 @@ in README."
(defun vterm--get-prompt-point ()
"Get the position of the end of current prompt.
More information see `vterm--prompt-tracking-enabled-p' and
-`Directory tracking and Prompt tracking'in README. "
+`Directory tracking and Prompt tracking'in README."
(let ((end-point (vterm--get-end-of-line))
prompt-point)
(save-excursion
@@ -1028,7 +1092,7 @@ More information see `vterm--prompt-tracking-enabled-p' and
(vterm--get-beginning-of-line))))))
(defun vterm--at-prompt-p ()
- "Check whether the cursor postion is at shell prompt or not."
+ "Return t if the cursor postion is at shell prompt."
(= (point) (vterm--get-prompt-point)))
(defun vterm-beginning-of-line ()
@@ -1043,13 +1107,11 @@ Effectively toggle between the two positions."
(goto-char (max (vterm--get-prompt-point)
(vterm--get-beginning-of-line)))))
-
(defun vterm-end-of-line ()
"Move point to the end of the line, bypassing line wraps."
(interactive)
(goto-char (vterm--get-end-of-line)))
-
(defun vterm-reset-cursor-point ()
"Make sure the cursor at the right postion."
(interactive)
@@ -1060,8 +1122,11 @@ Effectively toggle between the two positions."
(save-excursion
(vterm-reset-cursor-point)))
-
(defun vterm--remove-fake-newlines ()
+ "Filter out injected newlines were injected when rendering the terminal.
+
+These newlines were tagged with 'vterm-line-wrap property so we
+can find them and remove them."
(goto-char (point-min))
(let (fake-newline)
(while (setq fake-newline (next-single-property-change (point)
@@ -1072,6 +1137,7 @@ Effectively toggle between the two positions."
(delete-char 1)))))
(defun vterm--filter-buffer-substring (content)
+ "Filter string CONTENT of fake/injected newlines."
(with-temp-buffer
(insert content)
(vterm--remove-fake-newlines)