cpitclaudel/quick-peek

MELPA?

Closed this issue · 3 comments

Hi there,

I just stumbled upon this package by seeing that someone I follow on GitHub starred it. I'm very impressed! I've already come up with this, which shows peeks of items in Org agendas:

  (defun ap/org-agenda-quick-peek ()
    "Show quick peek of current item, or hide if one is already shown."
    (interactive)
    (if quick-peek--overlays
        (if (quick-peek--overlay-matches-pos (car quick-peek--overlays) (point))
            (quick-peek-hide)
          (quick-peek-hide)
          (ap/org-agenda-quick-peek--show))
      (ap/org-agenda-quick-peek--show)))

  (defun ap/org-agenda-quick-peek-all ()
    "Show/hide quick peek of all items."
    (interactive)
    (if quick-peek--overlays
        (quick-peek-hide)
      (goto-char (point-min))
      (cl-loop with lines = (count-lines (point-min) (point-max))
               while (< (line-number-at-pos) lines)
               do (ap/org-agenda-quick-peek--show :quiet t)
               (forward-line))))

  (cl-defun ap/org-agenda-quick-peek--show (&key (quiet nil))
    "Show quick peek at current line."
    (-if-let* ((m (org-get-at-bol 'org-hd-marker))
               (text (ap/s-trim-lines (org-agenda-get-some-entry-text m 10))))
        (if (s-present? text)
            (quick-peek-show text)
          (unless quiet
            (minibuffer-message "Entry has no text.")))))

Are you planning to put this on MELPA? I'd like to put up a package with Org-related quick-peeks like these, so I'd like to depend on a package of this. :)

Thanks a lot, this is a really nice package!

Thanks! See melpa/melpa#4656 :)

Btw, for the pattern that you're using (toggling the quick-peek window, you can call quick-peek-hide unconditionally (optionally with a position) and check the return value. That'll be a bit more simple (and robust) :)

Thanks!

FYI, here's what I'm using currently:

(use-package quick-peek
  :config

  (cl-defun ap/org-agenda-quick-peek--show (&key (quiet nil))
    "Show quick peek at current line."
    (-if-let* ((m (org-get-at-bol 'org-hd-marker))
               (text (ap/s-trim-lines (org-agenda-get-some-entry-text m 10))))
        (if (s-present? text)
            (quick-peek-show text)
          (unless quiet
            (minibuffer-message "Entry has no text.")))))

  (defun ap/org-peek-link ()
    "Show quick peek of org heading at link."
    (interactive)
    (unless (> (quick-peek-hide (point)) 0)
      ;; Showing, not hiding
      (save-excursion
        (let ((quick-peek-background-face '((t :background "black")))
              (org-show-hierarchy-above nil)
              (org-show-following-heading nil)
              (org-show-entry-below nil)
              (org-show-siblings nil)
              link type marker)

          ;; From org.el
          (when (and (looking-at org-complex-heading-regexp)
                     ;; (= (char-after (match-end 1)) ?\ )  ; Seems to be unnecessary
                     )
            ;; Move point to the beginning of the heading text so org-in-regexp
            ;; has a chance to match a link
            (goto-char (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
                            (point-at-eol))))

          ;; From org.el
          (when (org-in-regexp org-bracket-link-regexp 1)
            (setq link (org-extract-attributes
                        (org-link-unescape (org-match-string-no-properties 1))))
            (while (string-match " *\n *" link)
              (setq link (replace-match " " t t link)))
            (setq link (org-link-expand-abbrev link)))
          (when (string-match org-link-re-with-space3 link)
            (setq type (match-string 1 link)
                  path (match-string 2 link)))
          (when (and path
                     (string= type "id"))
            (setq marker (org-id-find path 'marker)))

          (save-current-buffer  ; Not sure if necessary
            (unless marker
              ;; Hopefully this will avoid calling org-open-at-point
              ;; most of the time, because org-open-at-point calls
              ;; org-show-context, which unnecessarily reveals hidden
              ;; nodes
              (org-open-at-point)
              (setq marker (point-marker))))
          (quick-peek-show (org-agenda-get-some-entry-text marker 10))))))

  (defun ap/org-cycle-after (&optional args)
    (save-excursion
      (when (re-search-forward org-bracket-link-regexp (line-end-position) t)
        (ap/org-peek-link))))
  (advice-add 'org-cycle :after 'ap/org-cycle-after)

  (defun ap/org-agenda-quick-peek ()
    "Show quick peek of current item, or hide if one is already shown."
    (interactive)
    (unless (> (quick-peek-hide (point)) 0)
      (ap/org-agenda-quick-peek--show)))

  (defun ap/org-agenda-quick-peek-all ()
    "Show/hide quick peek of all items."
    (interactive)
    (unless (> (quick-peek-hide (point)) 0)
      (goto-char (point-min))
      (cl-loop with lines = (count-lines (point-min) (point-max))
               while (< (line-number-at-pos) lines)
               do (ap/org-agenda-quick-peek--show :quiet t)
               (forward-line)))))

Now if point is at an Org heading which is a link to another heading, or if point is within any other link, pressing TAB will show a peek of the linked entry's contents. This is really cool. It lets you keep data in one node, link to that node at another place in the file, and display the linked node's contents at the link. This is something I've been wanting to do for a long time, and this package makes it so easy and clean!

It also shows entry text in agenda buffers in a nicer-looking way than the built-in entry text mode. For some reason it's much slower (like 2 or 3 orders of magnitude), but that's only an issue if you're showing all entry text for an entire agenda buffer. If I get around to profiling it and if I find any bottlenecks in quick-peek, I'll let you know; it might be an issue in my own code.

Anyway, this is all amazing. I think I'll have to put together an org-quick-peek package... ;)

@sudarshang I found this because you starred it, so in case you find this helpful... :)