Solution proposed by @T.Verron works, nevertheless sadly singular-interactive-mode
do not use comint
. So, here I propose another solution following @lawist suggestion. This code produces a function brust-math-software-hookfun-to-intangify-prompt
, which adds buffer-locally a function to after-change-functions
which properly properties the prompt accordingly to the list brust-math-software-buffers-prompts
.
You only need to add such a function to the hook of your mode.
And to add new languages you just need to update the list of buffers-prompts.
(defvar brust-math-software-buffers-prompts
'(("*julia*" . "^julia>")
("*singular*" . "^>"))
"List of cons with buffer names runing some math software and a regex for its promp string")
(defun brust-math-software-intangify-buffer-text (-regexp beg end)
"Set cursor-intangible property to all buffer text maching regular expresion `-regexp` between `beg` and `end`"
(save-excursion
(goto-char beg)
(save-match-data
(while (re-search-forward -regexp end t)
(add-text-properties (1- (match-beginning 0)) (match-end 0) '(cursor-intangible t rear-nonsticky nil))))))
(defun brust-math-software-intangify-cursor-on-prompt (beg end length)
"Set cursor-intangible in math software buffers prompts"
(let ((-prompt (cdr (assoc (buffer-name) brust-math-software-buffers-prompts))))
(when -prompt
(brust-math-software-intangify-buffer-text -prompt beg end))))
(defun brust-math-software-hookfun-to-intangify-prompt nil
(cursor-intangible-mode 1)
(add-hook 'after-change-functions #'brust-math-software-intangify-cursor-on-prompt nil t))
I have no idea why, but there is some incompatibility between properties cursor-intangible
and rear-nonsticky
.
So, the lines 2113--2124 from @T.Verron answer would be:
(add-text-properties prompt-start (point)
'(cursor-intangible t rear-nonsticky nil read-only t front-sticky (read-only)))))
julia >
and>
to see if some text property support is built-in (e.g., a color or something like that), or whether it needs to be added contemporaneously when the prompt is generated, or perhaps a solution has already been written up somewhere on the internet. Rather than having everyone Google the terms Julia REPL Emacs, perhaps you can provide a link to the source code that you are using ... – lawlist Nov 24 '19 at 21:08julia
I use ess (emacs speaks statistics) andjulia-mode
and for Singular https://github.com/Singular/Sources/tree/spielwiese/emacs – MonLau Nov 24 '19 at 21:29font-lock-add-keywords
– MonLau Nov 24 '19 at 21:36after-change-functions
hook ... "List of functions to call after each text change....". There may be other hooks on the list that could be of assistance. – lawlist Nov 24 '19 at 22:10comint-prompt-read-only
tot
work? Otherwise, I believe that you can adapt line 2113 to 2124 in https://github.com/emacs-mirror/emacs/blob/master/lisp/comint.el to get what you want (assuming that the REPL's are powered by comint). – T. Verron Nov 24 '19 at 22:49move-beginning-of-line
. I will try to modify lines 2113--2124, that will work for every mode usingcomint
– MonLau Nov 24 '19 at 23:02