-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Full inferior mode input font locking #1428
Comments
Here is an improvement on the above code:
(defun elpy-shell--insert-and-font-lock (string face &optional no-font-lock)
"Inject STRING into the Python shell buffer."
(let ((from-point (point)))
(insert string)
(if (not no-font-lock)
(if (eq face 'comint-highlight-input)
(python-shell-font-lock-post-command-hook)
(add-text-properties from-point (point)
(list 'front-sticky t 'font-lock-face face))))))
(advice-add 'comint-send-input
:around (lambda (f &rest args)
(when (eq major-mode 'inferior-python-mode)
(cl-letf ((g (symbol-function 'add-text-properties))
((symbol-function 'add-text-properties)
(lambda (start end properties &optional object)
(unless (eq (nth 3 properties) 'comint-highlight-input)
(funcall g start end properties object)))))
(apply f args))))) Notice I had to redefine I understand all this is a workaround but the results look really nice! I suggest elpy to implement the above but in a more cleanly fashion:
What do you think? (And please, give it a try, I believe once you saw the colors in your comint buffer you would want to add this!) |
The above was intended to suggest how this could be added as part of elpy. If anyone is wanting to hack his/her config right now, I would recommend to advice elpy-shell--insert-and-font-lock instead of overwriting it: (advice-add 'elpy-shell--insert-and-font-lock
:around (lambda (f string face &optional no-font-lock)
(if (not (eq face 'comint-highlight-input))
(funcall f string face no-font-lock)
(funcall f string face t)
(python-shell-font-lock-post-command-hook)))) |
I've added a subsection to the wiki listing both advices https://github.com/jorgenschaefer/elpy/wiki/Customizations#enable-full-font-locking-of-inputs-in-the-python-shell |
Thank you for the suggestion! I like the idea, but I would prefer not having to maintain this code in the future. Having it in comint would be great, in the meantime, having it in the wiki is a good workaround. Thanks again! :-) |
@galaunay I'm trying to push the required changes into comint so as we can have full font locking in inferior shell, maybe you could express your interest in that feature in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32344. Thanks. |
I would ne very pleased for this to be merged as well. |
I know this is a comint issue and I've already reported at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=32344 (please see details there).
But maybe you're interested in adding this workaround to elpy (perhaps optionally depending on a customization option) in order to get full input font locking, it looks really nice!
The text was updated successfully, but these errors were encountered: