aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-prog.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-prog.el')
-rw-r--r--emacs/.emacs.d/lisp/my/my-prog.el124
1 files changed, 123 insertions, 1 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el
index 9c75a22..92fcf21 100644
--- a/emacs/.emacs.d/lisp/my/my-prog.el
+++ b/emacs/.emacs.d/lisp/my/my-prog.el
@@ -365,7 +365,100 @@ left and the source buffer on the right.
(select-window (display-buffer (gdb-get-source-buffer))))
(defun my-gud-comint-set-prompt-regexp ()
- (setq comint-prompt-regexp "\\((rr)|(gdb)\\) "))
+ (setq comint-prompt-regexp "\\((rr)\\|(gdb)\\) *"))
+
+(defun my-gud-source-line ()
+ (with-current-buffer (gdb-get-source-buffer)
+ (buffer-substring (progn (beginning-of-line) (point))
+ (progn (end-of-line) (point)))))
+
+(defun my-gud-function-name ()
+ (with-current-buffer (gdb-get-source-buffer)
+ (which-function)))
+
+(defun my-gud-insert-source-line ()
+ (interactive)
+ (insert (my-gud-source-line)))
+
+(defun my-gud-insert-function-name ()
+ (interactive)
+ (insert (my-gud-function-name)))
+
+(defun my-gud-insert-source-line-and-function-name ()
+ (interactive)
+ (insert (format "%s IN %s" (my-gud-source-line) (my-gud-function-name))))
+
+;;; used to override `gdb-frame-handler': do not re-display frame on
+;;; completion.
+(defun my-gdb-frame-handler ()
+ "Set `gdb-selected-frame' and `gdb-selected-file' to show
+overlay arrow in source buffer."
+ (let ((frame (gdb-mi--field (gdb-mi--partial-output) 'frame)))
+ (when frame
+ (setq gdb-selected-frame (gdb-mi--field frame 'func))
+ (setq gdb-selected-file
+ (when-let ((full (gdb-mi--field frame 'fullname)))
+ (file-local-name full)))
+ (setq gdb-frame-number (gdb-mi--field frame 'level))
+ (setq gdb-frame-address (gdb-mi--field frame 'addr))
+ (let ((line (gdb-mi--field frame 'line)))
+ (setq gdb-selected-line (and line (string-to-number line)))
+ (when (and gdb-selected-file gdb-selected-line
+ (not (and (boundp 'gud-gdb-fetch-lines-break)
+ gud-gdb-fetch-lines-break)))
+ (setq gud-last-frame (cons gdb-selected-file gdb-selected-line))
+ (gud-display-frame)))
+ (if gud-overlay-arrow-position
+ (let ((buffer (marker-buffer gud-overlay-arrow-position))
+ (position (marker-position gud-overlay-arrow-position)))
+ (when buffer
+ (with-current-buffer buffer
+ (setq fringe-indicator-alist
+ (if (string-equal gdb-frame-number "0")
+ nil
+ '((overlay-arrow . hollow-right-triangle))))
+ (setq gud-overlay-arrow-position (make-marker))
+ (set-marker gud-overlay-arrow-position position))))))))
+
+
+;;; Can't override gud-gdbmi-completions - would get:
+;;; error in process filter: gud-marker-filter: Symbol’s value as variable is void: gud-gdb-fetch-lines-string
+;;; error in process filter: Symbol’s value as variable is void: gud-gdb-fetch-lines-string
+
+;; (defun gud-gdbmi-completions (context command)
+;; "Completion table for GDB/MI commands.
+;; COMMAND is the prefix for which we seek completion.
+;; CONTEXT is the text before COMMAND on the line."
+;; (let ((gud-gdb-fetch-lines-in-progress t)
+;; (gud-gdb-fetch-lines-string nil)
+;; (gud-gdb-fetch-lines-break (length context))
+;; (gud-gdb-fetched-lines nil)
+;; ;; This filter dumps output lines to `gud-gdb-fetched-lines'.
+;; (gud-marker-filter #'gud-gdbmi-fetch-lines-filter))
+;; (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
+;; (gdb-input (concat "complete " context command)
+;; (lambda () (setq gud-gdb-fetch-lines-in-progress nil)))
+;; (while gud-gdb-fetch-lines-in-progress
+;; (accept-process-output (get-buffer-process gud-comint-buffer) .1)))
+;; (gud-gdb-completions-1 gud-gdb-fetched-lines)))
+
+(defun my-gud-watch-expr (expr)
+ (with-current-buffer gud-comint-buffer
+ (insert "watch -l " expr)
+ (comint-send-input)))
+
+(defun my-gud-print-expr (expr)
+ (with-current-buffer gud-comint-buffer
+ (insert "p " expr)
+ (comint-send-input)))
+
+(defun my-gud-print-expr-region (b e)
+ (interactive "r")
+ (unless (eq (gdb-get-source-buffer) (current-buffer))
+ (error "Not in the source buffer"))
+ (if current-prefix-arg
+ (my-gud-watch-expr (buffer-substring b e))
+ (my-gud-print-expr (buffer-substring b e))))
;;; which-func
(defun my-copy-which-func ()
@@ -434,6 +527,34 @@ left and the source buffer on the right.
(unless (derived-mode-p 'haskell-mode 'c-mode 'c++-mode)
(eglot-format-buffer))))
+;;; https://github.com/joaotavora/eglot/issues/88
+(defun my-eglot-ccls-inheritance-hierarchy (&optional derived)
+ "Show inheritance hierarchy for the thing at point.
+If DERIVED is non-nil (interactively, with prefix argument), show
+the children of class at point."
+ (interactive "P")
+ (if-let* ((res (jsonrpc-request
+ (eglot--current-server-or-lose)
+ :$ccls/inheritance
+ (append (eglot--TextDocumentPositionParams)
+ `(:derived ,(if derived t :json-false))
+ '(:levels 100) '(:hierarchy t))))
+ (tree (list (cons 0 res))))
+ (with-help-window "*ccls inheritance*"
+ (with-current-buffer standard-output
+ (while tree
+ (pcase-let ((`(,depth . ,node) (pop tree)))
+ (cl-destructuring-bind (&key uri range) (plist-get node :location)
+ (insert (make-string depth ?\ ) (plist-get node :name) "\n")
+ (make-text-button (+ (point-at-bol 0) depth) (point-at-eol 0)
+ 'action (lambda (_arg)
+ (interactive)
+ (find-file (eglot--uri-to-path uri))
+ (goto-char (car (eglot--range-region range)))))
+ (cl-loop for child across (plist-get node :children)
+ do (push (cons (1+ depth) child) tree)))))))
+ (eglot--error "Hierarchy unavailable")))
+
;;; lisp
(defun my-eval-defun-or-region (&optional arg)
"Call `eval-region' if region is active, otherwise call `eval-defun'"
@@ -461,6 +582,7 @@ left and the source buffer on the right.
(auto-fill-mode)
(display-line-numbers-mode)
(setq tab-width 2)
+ (setq indent-tabs-mode nil)
(bug-reference-prog-mode)
(flyspell-prog-mode))