Skip to content

Commit

Permalink
Fix: Eldoc inner symbol getter robust, no error on some dot dsl case
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaschalk committed May 30, 2019
1 parent dd0878e commit 051bc4a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 60 deletions.
85 changes: 40 additions & 45 deletions hy-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

(require 'hy-base)

;; TODO Add a hy-syntax and hy-jedhy pkgs
;; TODO Add a hy-config file?
(require 'hy-font-lock)
(require 'hy-shell)

Expand Down Expand Up @@ -206,44 +208,44 @@ commands."

;;; Describe thing at point

(defun hy--docs-for-thing-at-point ()
"Mirrors `hy-eldoc-documentation-function' formatted for a buffer, not a msg."
(-> (thing-at-point 'symbol)
(hy--eldoc-get-docs t)
hy--format-docs-for-buffer))

(defun hy--format-docs-for-buffer (text)
"Format raw hydoc TEXT for inserting into hyconda buffer."
(-let [kwarg-newline-regexp
(rx ","
(1+ (not (any "," ")")))
(group-n 1 "\\\n")
(1+ (not (any "," ")"))))]
(-some--> text
(s-replace "\\n" "\n" it)
(replace-regexp-in-string kwarg-newline-regexp
"newline" it nil t 1))))

(defun hy-describe-thing-at-point ()
"Implement shift-k docs lookup for `spacemacs/evil-smart-doc-lookup'."
(interactive)
(-when-let* ((text (hy--docs-for-thing-at-point))
(doc-buffer "*Hyconda*"))
(with-current-buffer (get-buffer-create doc-buffer)
(erase-buffer)
(switch-to-buffer-other-window doc-buffer)

(insert text)
(goto-char (point-min))
(forward-line)

(insert "------\n")
(fill-region (point) (point-max))

;; Eventually make hyconda-view-minor-mode, atm this is sufficient
(local-set-key "q" 'quit-window)
(when (fboundp 'evil-local-set-key)
(evil-local-set-key 'normal "q" 'quit-window)))))
;; (defun hy--docs-for-thing-at-point ()
;; "Mirrors `hy-eldoc-documentation-function' formatted for a buffer, not a msg."
;; (-> (thing-at-point 'symbol)
;; (hy--eldoc-get-docs t)
;; hy--format-docs-for-buffer))

;; (defun hy--format-docs-for-buffer (text)
;; "Format raw hydoc TEXT for inserting into hyconda buffer."
;; (-let [kwarg-newline-regexp
;; (rx ","
;; (1+ (not (any "," ")")))
;; (group-n 1 "\\\n")
;; (1+ (not (any "," ")"))))]
;; (-some--> text
;; (s-replace "\\n" "\n" it)
;; (replace-regexp-in-string kwarg-newline-regexp
;; "newline" it nil t 1))))

;; (defun hy-describe-thing-at-point ()
;; "Implement shift-k docs lookup for `spacemacs/evil-smart-doc-lookup'."
;; (interactive)
;; (-when-let* ((text (hy--docs-for-thing-at-point))
;; (doc-buffer "*Hyconda*"))
;; (with-current-buffer (get-buffer-create doc-buffer)
;; (erase-buffer)
;; (switch-to-buffer-other-window doc-buffer)

;; (insert text)
;; (goto-char (point-min))
;; (forward-line)

;; (insert "------\n")
;; (fill-region (point) (point-max))

;; ;; Eventually make hyconda-view-minor-mode, atm this is sufficient
;; (local-set-key "q" 'quit-window)
;; (when (fboundp 'evil-local-set-key)
;; (evil-local-set-key 'normal "q" 'quit-window)))))

;;; Keybindings

Expand Down Expand Up @@ -371,17 +373,10 @@ commands."
(add-to-list 'auto-mode-alist '("\\.hy\\'" . hy-mode))
(add-to-list 'interpreter-mode-alist '("hy" . hy-mode))

;; Now done in `hy-shell'
;;;###autoload
;; (define-derived-mode inferior-hy-mode comint-mode "Inferior Hy"
;; "Major mode for Hy inferior process."
;; (hy--inferior-mode-setup))

;;;###autoload
(define-derived-mode hy-mode prog-mode "Hy"
"Major mode for editing Hy files."
(hy--mode-setup-font-lock)
;; FIXME IDE Features being re-integrated
(hy--mode-setup-eldoc)
(hy--mode-setup-smartparens)
(hy--mode-setup-syntax))
Expand Down
30 changes: 15 additions & 15 deletions hy-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,20 @@ Expected to be called within a Hy interpreter process buffer."
(-when-let (inner-symbol (and (hy--goto-inner-sexp (syntax-ppss))
(not (-contains? '(?\[ ?\{) (char-before)))
(thing-at-point 'symbol)))
(if (not (and (hy-shell--method-call? inner-symbol)
(ignore-errors (forward-sexp) (forward-char) t)))
inner-symbol
(if (hy-shell--method-call? inner-symbol)
(when (ignore-errors (forward-sexp) (forward-whitespace 1) t)
(pcase (char-after)
;; Can't send just .method to eldoc
((or ?\) ?\s ?\C-j) nil)

(pcase (char-after)
;; Can't send just .method to eldoc
((or ?\) ?\s ?\C-j) nil)
;; Dot dsl doesn't work on literals
(?\[ (s-concat "list" inner-symbol))
(?\{ (s-concat "dict" inner-symbol))
(?\" (s-concat "str" inner-symbol))

;; Dot dsl doesn't work on literals
(?\[ (s-concat "list" inner-symbol))
(?\{ (s-concat "dict" inner-symbol))
(?\" (s-concat "str" inner-symbol))

;; Otherwise complete the dot dsl
(_ (progn (forward-char)
(s-concat (thing-at-point 'symbol) inner-symbol))))))))
;; Otherwise complete the dot dsl
(_ (s-concat (thing-at-point 'symbol) inner-symbol))))
inner-symbol))))

;;;; Output Formats

Expand Down Expand Up @@ -447,7 +445,9 @@ Expected to be called within a Hy interpreter process buffer."

(defun hy-eldoc-documentation-function ()
"Drives `eldoc-mode', retrieves eldoc msg string for inner-most symbol."
(hy-shell--candidate-str->eldoc (thing-at-point 'symbol)))
;; (hy-shell--candidate-str->eldoc (thing-at-point 'symbol))
(hy-shell--candidate-str->eldoc (hy-shell--get-inner-symbol))
)

(defun company-hy (command &optional prefix-or-candidate-str &rest ignored)
(interactive (list 'interactive))
Expand Down

0 comments on commit 051bc4a

Please sign in to comment.