branch: externals/dape
commit 8418a68442c772828ccdc901c286398e69670c21
Author: Daniel Pettersson <[email protected]>
Commit: Daniel Pettersson <[email protected]>

    Fix repl faces
---
 README.org |   2 +-
 dape.el    | 101 ++++++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 61 insertions(+), 42 deletions(-)

diff --git a/README.org b/README.org
index 94e2ee6dc8..73238327eb 100644
--- a/README.org
+++ b/README.org
@@ -55,7 +55,7 @@ Dape has no dependencies outside of packages included in 
emacs, and tries to use
 Dape takes a slightly different approach to configuration.
 + Dape does not support ~launch.json~ files, if per project configuration is 
needed use ~dir-locals~.
 + Tries to simplify configuration, by having just a plist.
-+ Dape tries to improve config ergonomics in ~dape~ completing-read by 
allowing to change/add plist entries in an already existing config, example: 
~adapter-config :program "/home/user/b.out" :compile "gcc -g -o b.out main.c "~.
++ Dape tries to improve config ergonomics in ~dape~ completing-read by using 
options to change/add plist entries in an already existing config, example: 
~adapter-config :program "/home/user/b.out" :compile "gcc -g -o b.out main.c"~.
 + No magic, no special variables. Instead, functions and variables are 
resolved before starting a new session.
 + No batteries included. Many, suffer from a significant drawback: they're 
tightly coupled with the vscode extension they're bundled with. This tight 
coupling results in launch/attach requests being specific to each adapter, 
devoid of reasonable defaults as they are stored within the extension itself, 
leading to an ever-changing and unstable API. Consequently, attempting to 
include default configurations for each adapter seems like a losing proposition.
 + Tries to be envision to how debug adapter configuration would be implemented 
in emacs if vscode never existed.
diff --git a/dape.el b/dape.el
index 1b217bdf97..0f546d21d6 100644
--- a/dape.el
+++ b/dape.el
@@ -184,6 +184,15 @@ The hook is run with one argument, the compilation buffer."
   '((t :inherit highlight :extend t))
   nil)
 
+(defface dape-repl-exit-code-exit
+  '((t :inherit compilation-mode-line-exit :extend t))
+  nil)
+
+(defface dape-repl-exit-code-fail
+  '((t :inherit compilation-mode-line-fail :extend t))
+  nil)
+
+
 
 ;;; Vars
 
@@ -835,30 +844,23 @@ The hook is run with one argument, the compilation 
buffer."
      ((equal category "stdout")
       (dape--repl-insert-text (plist-get body :output)))
      ((equal category "stderr")
-      (dape--repl-insert-text (propertize
-                               (plist-get body :output)
-                               'face 'error)))
+      (dape--repl-insert-text (plist-get body :output) 'error))
      ((or (equal category "console")
           (equal category "output"))
-      (dape--repl-insert-text (propertize
-                               (plist-get body :output)
-                               'face 'italic))))))
+      (dape--repl-insert-text (plist-get body :output) 'italic)))))
 
 (cl-defmethod dape-handle-event (_process (_event (eql exited)) body)
   (dape--update-state "exited")
   (dape--remove-stack-pointers)
-  (dape--repl-insert-text (propertize
-                           (format "* Exit code: %d *\n"
-                                   (plist-get body :exitCode))
-                           'face
-                           'highlight)))
+  (dape--repl-insert-text (format "* Exit code: %d *\n"
+                                  (plist-get body :exitCode))
+                          (if (zerop (plist-get body :exitCode))
+                              'dape-repl-exit-code-exit
+                            'dape-repl-exit-code-fail)))
 
 (cl-defmethod dape-handle-event (_process (_event (eql terminated)) _body)
   (dape--update-state "terminated")
-  (dape--repl-insert-text (propertize
-                           "* Program terminated *\n"
-                           'face
-                           'highlight))
+  (dape--repl-insert-text "* Program terminated *\n" 'italic)
   (dape--remove-stack-pointers))
 
 
@@ -1728,6 +1730,9 @@ Watched symbols are displayed in *dape-info* buffer.
                                (plist-get exception :label))
                :value (plist-get exception :enabled)
                :action (lambda (&rest args)
+                         ;; HACK updates exceptions tree after enabling 
exception
+                         ;;      this is only only done to get the current
+                         ;;      exception object.
                          (plist-put exception :enabled
                                     (not (plist-get exception :enabled)))
                          (dape--set-exception-breakpoints
@@ -1780,6 +1785,7 @@ Depending on line in *dape-info* buffer."
 (define-derived-mode dape-info-mode special-mode "Dape info"
   "Dape info mode is displays various dape related information.
 See `dape-info' for more information."
+  :group 'dape
   :interactive nil
   (let ((inhibit-read-only t))
     (erase-buffer))
@@ -1870,7 +1876,7 @@ Buffer contains debug session information."
 (defun dape--completion-frame-id ()
   (plist-get (dape--current-stack-frame) :id))
 
-(defun dape--repl-insert-text (msg)
+(defun dape--repl-insert-text (msg &optional face)
   (cond
    (dape--repl-insert-text-guard
     (run-with-timer 0.1 nil 'dape--repl-insert-text msg))
@@ -1891,14 +1897,16 @@ Buffer contains debug session information."
                       (let ((inhibit-read-only t))
                         (insert "\n"))))
                   (let ((inhibit-read-only t))
-                    (insert msg)))
+                    (insert (propertize msg 'font-lock-face face))))
               (error
                (setq dape--repl-insert-text-guard nil)
                (signal (car err) (cdr err))))
             (setq dape--repl-insert-text-guard nil))))
       (unless (get-buffer-window "*dape-repl*")
         (when (stringp msg)
-          (message "%s" (string-trim msg "\\\n" "\\\n"))))))))
+          (message (format "%s"
+                           (string-trim msg "\\\n" "\\\n"))
+                   'face face)))))))
 
 (defun dape--repl-input-sender (dummy-process input)
   (let (cmd)
@@ -1943,7 +1951,7 @@ Buffer contains debug session information."
        (t
         (comint-output-filter
          dummy-process
-         (format "* Unable to send \"%s\", no stopped threads *\n> "
+         (format "* Unable to send \"%s\" no stopped threads *\n> "
                  input)))))))
 
 (defun dape--repl-completion-at-point ()
@@ -2033,15 +2041,21 @@ Buffer contains debug session information."
                               nil nil 'equal)))
          annotation)))))
 
+
+(defvar dape--repl--prompt "> ")
+(defvar dape-repl-mode nil)
+
 (define-derived-mode dape-repl-mode comint-mode "Dape REPL"
-  (add-hook 'completion-at-point-functions
-            #'dape--repl-completion-at-point
-            nil
-            t)
-  (setq-local comint-prompt-read-only t
+  :group 'dape
+  :interactive nil
+  (when dape-repl-mode
+    (user-error "`dape-repl-mode' all ready enabled."))
+  (setq-local dape-repl-mode t
+              comint-prompt-read-only t
               comint-input-sender 'dape--repl-input-sender
-              comint-use-prompt-regexp nil
+              comint-prompt-regexp (concat "^" (regexp-quote 
dape--repl--prompt))
               comint-process-echoes nil)
+  (add-hook 'completion-at-point-functions #'dape--repl-completion-at-point 
nil t)
   ;; Stolen from ielm
   ;; Start a dummy process just to please comint
   (unless (comint-check-proc (current-buffer))
@@ -2050,22 +2064,26 @@ Buffer contains debug session information."
                                     nil)
     (set-process-filter (get-buffer-process (current-buffer))
                         'comint-output-filter)
-    (comint-output-filter (get-buffer-process (current-buffer))
-                          (format
-                           "Welcome to Dape REPL!
+    (insert (propertize
+               (format
+                "* Welcome to Dape REPL! *
 Available Dape commands: %s
-Empty input will rerun last command.\n\n\n> "
-                           (mapconcat 'identity
-                                      (mapcar (lambda (cmd)
-                                                (let ((str (car cmd)))
-                                                  (if dape-repl-use-shorthand
-                                                      (concat "["
-                                                              (substring str 0 
1)
-                                                              "]"
-                                                              (substring str 
1))
-                                                    str)))
-                                              dape-repl-commands)
-                                      ", ")))))
+Empty input will rerun last command.\n\n\n"
+                (mapconcat 'identity
+                           (mapcar (lambda (cmd)
+                                     (let ((str (car cmd)))
+                                       (if dape-repl-use-shorthand
+                                           (concat "["
+                                                   (substring str 0 1)
+                                                   "]"
+                                                   (substring str 1))
+                                         str)))
+                                   dape-repl-commands)
+                           ", "))
+               'font-lock-face 'italic))
+    (set-marker (process-mark (get-buffer-process (current-buffer))) (point))
+    (comint-output-filter (get-buffer-process (current-buffer))
+                          dape--repl--prompt)))
 
 (defun dape-repl ()
   "Create or select *dape-repl* buffer."
@@ -2073,7 +2091,8 @@ Empty input will rerun last command.\n\n\n> "
   (let ((buffer-name "*dape-repl*")
         window)
     (with-current-buffer (get-buffer-create buffer-name)
-      (dape-repl-mode)
+      (unless dape-repl-mode
+        (dape-repl-mode))
       (setq window (display-buffer (current-buffer)
                                    '((display-buffer-reuse-window
                                       display-buffer-in-side-window)

Reply via email to