Git Product home page Git Product logo

Comments (3)

aikrahguzar avatar aikrahguzar commented on August 27, 2024 1

It doesn't let me convert this into a draft, but consider this PR on pause until I investigate your solution. Hopefully this can be fixed upstream in eshell-syntax-highlighting and without any changes here.

This is an issue. You probably meant the pr on the doom repo?

from eshell-syntax-highlighting.

aikrahguzar avatar aikrahguzar commented on August 27, 2024

This is a solution using indirect buffers,

diff --git a/eshell-syntax-highlighting.el b/eshell-syntax-highlighting.el
index 7d06304..7cd4e82 100644
--- a/eshell-syntax-highlighting.el
+++ b/eshell-syntax-highlighting.el
@@ -167,25 +167,34 @@
            (t 'eshell-syntax-highlighting-default-face))))
     (add-face-text-property beg end face)))
 
+(defvar eshell-syntax-highlighting--indirect-lisp-buffer nil)
+
+(defun eshell-syntax-highlighting--indriect-buffer ()
+  (or
+   eshell-syntax-highlighting--indirect-lisp-buffer
+   (with-current-buffer
+       (setq-local eshell-syntax-highlighting--indirect-lisp-buffer
+                   (make-indirect-buffer
+                    (current-buffer)
+                    (generate-new-buffer-name
+                     (concat " " (buffer-name) "-eshell-indirect"))))
+     (setq-local delay-mode-hooks t)
+     (let ((change-major-mode-hook nil)
+           (after-change-major-mode-hook nil))
+       (emacs-lisp-mode))
+     (setq-local font-lock-dont-widen t)
+     (setq-local font-lock-support-mode nil))
+   comint--indirect-buffer))
+
 (defun eshell-syntax-highlighting--highlight-elisp (beg end)
   "Highlight Emacs Lisp in region (BEG, END) natively through a temp buffer."
-  (let* ((elisp-end (condition-case
-                        nil (scan-sexps beg 1)
-                      (scan-error end)))
-         (str (buffer-substring-no-properties beg elisp-end)))
-    (if (not eshell-syntax-highlighting-highlight-elisp)
-        (eshell-syntax-highlighting--highlight beg (point) 'default)
-      (goto-char beg)
-      (insert
-       (with-temp-buffer
-         (erase-buffer)
-         (insert str)
-         (delay-mode-hooks (emacs-lisp-mode))
-         (font-lock-default-function 'emacs-lisp-mode)
-         (font-lock-default-fontify-region (point-min) (point-max) nil)
-         (buffer-string)))
-      (delete-region (point) (+ (point) (length str))))
-    (goto-char elisp-end)))
+    (let ((elisp-end (condition-case nil
+                         (scan-sexps beg 1)
+                       (scan-error end))))
+      (with-current-buffer (eshell-syntax-highlighting--indriect-buffer)
+        (narrow-to-region beg elisp-end)
+        (font-lock-ensure beg elisp-end))
+      (goto-char elisp-end)))
 
 (defun eshell-syntax-highlighting--highlight-substitutions (beg end)
   "Find and highlight command substitutions in region (BEG, END)."

It is probably better to go the way of comint-fontify-input-mode and allow running a setup hook in the indirect buffer. E.g. I would like it to turn on highlight-quoted-mode.

from eshell-syntax-highlighting.

LemonBreezes avatar LemonBreezes commented on August 27, 2024

This is a solution using indirect buffers,
...

It doesn't let me convert this into a draft, but consider this PR on pause until I investigate your solution. Hopefully this can be fixed upstream in eshell-syntax-highlighting and without any changes here.

from eshell-syntax-highlighting.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.