jojojames / smart-jump

GNU General Public License v3.0
121 stars 12 forks source link

+TITLE: Smart Jump

[[https://travis-ci.org/jojojames/smart-jump][file:https://travis-ci.org/jojojames/smart-jump.svg?branch=master]] [[https://melpa.org/#/smart-jump][file:https://melpa.org/packages/smart-jump-badge.svg]]

+begin_src emacs-lisp :tangle yes

(use-package smart-jump :ensure t :bind (("M-." . smart-jump-go) ("M-," . smart-jump-back) ("M-?" . smart-jump-references)))

+end_src

Defer smart-jump by using :bind.

+begin_src emacs-lisp :tangle yes

(use-package smart-jump :ensure t :commands (smart-jump-go smart-jump-back smart-jump-references) :init (with-eval-after-load 'general (general-define-key :states '(normal visual motion) :keymaps 'override "M-." 'smart-jump-go "M-," 'smart-jump-back "M-?" 'smart-jump-references)))

+end_src

Defer smart-jump in evil with general.

The deferred approaches allows one to save some startup-time by avoiding having to load the package as well as loop through all the jump registrations.

(defun smart-jump-make-peek-frame (find-definition-function &rest args) "Make a new frame for peeking definition.

Credits to @tuhdo.

http://tuhdo.github.io/emacs-frame-peek.html" (let (doc-frame x y ;; 1. Find the absolute position of the current beginning of the ;; symbol at point, in pixels. (abs-pixel-pos (save-excursion ;; (beginning-of-thing 'symbol) (beginning-of-line) (window-absolute-pixel-position)))) (setq x (car abs-pixel-pos)) (setq y (+ (cdr abs-pixel-pos) (frame-char-height)))

;; 2. Create a new invisible frame, with the current buffer in it.
(setq doc-frame (make-frame '((name . "*SmartJump Peek*")
                              (width . 80)
                              (visibility . nil)
                              (height . 20)
                              (min-width  . t)
                              (min-height . t)
                              (border-width . 0)
                              (internal-border-width . 0)
                              (vertical-scroll-bars . nil)
                              (horizontal-scroll-bars . nil)
                              (left-fringe . 0)
                              (right-fringe . 0)
                              (tool-bar-lines . 0)
                              (line-spacing . 0)
                              (unsplittable . t)
                              (no-other-frame . t)
                              (no-special-glyphs . t))))

;; 3. Position the new frame right under the beginning of the
;; symbol at point.
(set-frame-position doc-frame x y)

;; 4. Jump to the symbol at point.
(with-selected-frame doc-frame
  (apply find-definition-function args)
  (recenter-top-bottom 0))

;; 5. Make frame visible again.
(make-frame-visible doc-frame)))

+end_src