Skip to content

Commit

Permalink
Use text property to store source file
Browse files Browse the repository at this point in the history
Because now this is easier than elisp-demos-find-demo.
  • Loading branch information
xuchunyang committed Jan 16, 2024
1 parent b6bea11 commit 930ae5e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions elisp-demos.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ If set, new notes are added to the first file in this list."
(when-let ((pos (org-find-exact-headline-in-buffer (symbol-name symbol))))
(goto-char pos)
(org-end-of-meta-data)
(push (string-trim
(buffer-substring-no-properties
(point)
(org-end-of-subtree)))
(push (propertize
(string-trim
(buffer-substring-no-properties
(point)
(org-end-of-subtree)))
'file file
'pos (marker-position pos))

This comment has been minimized.

Copy link
@jcs090218

jcs090218 Jan 19, 2024

Any reason to use org.el? Now, it is impossible to use this package with company-mode (doc-buffer) on Windows since it will take a significant time to load. 😢

This comment has been minimized.

Copy link
@xuchunyang

xuchunyang Jan 19, 2024

Author Owner

Several org mode functions were used during supporting elisp-demos-user-files and other features in #18 by @sachac , e.g.,

  • org-find-exact-headline-in-buffer
  • org-end-of-subtree
  • org-entry-get
  • org-insert-heading

I prefered simple solutions without org.el because of simplicity and efficiency, but using more org.el specific features also seemed fine to me. I will try to use company mode with doc-buffer to see what's the issue. Anyway, elisp-demos.org is a very simple format so we should be able to resolve the issue.

This comment has been minimized.

Copy link
@xuchunyang

xuchunyang Jan 19, 2024

Author Owner

@jcs090218 elisp-demos--search is now free of org.el since last commit 90bd2d6, I hope it helps.

This comment has been minimized.

Copy link
@jcs090218

jcs090218 Jan 20, 2024

I will try to use company mode with doc-buffer to see what's the issue.

For clarification, I'm using company-box, and this line takes up some times:

https://github.com/sebastiencs/company-box/blob/b6f53e26adf948aca55c3ff6c22c21a6a6614253/company-box-doc.el#L76

After calling (org-load-modules-maybe) , it appears to return to normal. And again, this function takes up 5 to 10 seconds to load. 🤔

elisp-demos--search is now free of org.el since last commit 90bd2d6, I hope it helps.

I reckon it's slightly faster, but unfortunately, it doesn't really help much since it's still unusable in Windows. 😢

This comment has been minimized.

Copy link
@sachac

sachac via email Jan 20, 2024

Contributor

This comment has been minimized.

Copy link
@jcs090218

jcs090218 Jan 20, 2024

Since company-box-doc displays documentation in another frame and might be
called many times,

No, it does not. It's straightforward frontend plugin for company-mode, so it would only be called when needed.

does it make sense to refine the advice so that it
doesn't add elisp-demos during completion, just for describe-function?

It's definitely possible! However, it was one of the best features, so I wouldn't want to eliminate it.

This comment has been minimized.

Copy link
@xuchunyang

xuchunyang Jan 20, 2024

Author Owner

@jcs090218 Org Mode has been necessary and utilized for syntax highlighting through (delay-mode-hooks (org-mode)) since the inception of the package in 2018. Have you only recently become aware of this issue?

I don't have much experience with org.el and company-mode, they are both too complex to understand for me. I tried company-box and didn't get it to work.

This comment has been minimized.

Copy link
@jcs090218

jcs090218 Jan 20, 2024

Have you only recently become aware of this issue?

Absolutely! The last version that worked for me is elisp-demos-20230726.2059 (8d0cd80).

I don't have much experience with org.el and company-mode, they are both too complex to understand for me. I tried company-box and didn't get it to work.

The problem is the macro while-no-input. In the functioning version, the doc buffer happens within split seconds, ensuring the frame is displayed promptly. In the current master branch, it takes longer, creating the impression that it might not be displayed. 🤔

This comment has been minimized.

Copy link
@xuchunyang

xuchunyang Jan 20, 2024

Author Owner

@jcs090218 I just removed (require 'org) in d03e4e8. It will cause some byte compiler warnings but I think that's fine.

results)))))
(when results
(string-join (nreverse results) "\n\n"))))
Expand Down Expand Up @@ -165,11 +168,10 @@ If set, new notes are added to the first file in this list."
(defun elisp-demos-help-find-demo-at-point ()
"Find the demo at point."
(interactive)
(let ((offset (- (point) (get-text-property (point) 'start))))
(and (elisp-demos-find-demo (get-text-property (point) 'symbol))
;; Skip heading and an empty line
(forward-line 2)
(forward-char offset))))
(let ((file (get-text-property (point) 'file))
(pos (get-text-property (point) 'pos)))
(find-file file)
(goto-char pos)))

(defvar elisp-demos-help-keymap
(let ((map (make-sparse-keymap)))
Expand Down Expand Up @@ -230,7 +232,10 @@ If set, new notes are added to the first file in this list."
(defun elisp-demos-for-helpful ()
"Find a demo for the current `helpful' buffer."
(interactive)
(elisp-demos-find-demo helpful--sym))
(let ((file (get-text-property (point) 'file))
(pos (get-text-property (point) 'pos)))
(find-file file)
(goto-char pos)))

;;; * JSON

Expand Down

3 comments on commit 930ae5e

@sachac
Copy link
Contributor

@sachac sachac commented on 930ae5e Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry about that! I used Org functions so that headings could have TODO keywords and tags, but maybe that's not necessary.

@xuchunyang
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see, I will try to reduce the use of features from org.el to keep elisp-demo.el lightweight.

@sachac
Copy link
Contributor

@sachac sachac commented on 930ae5e Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your thoughtfulness about older versions of Emacs and of other hardware. Sorry for the extra work!

Please sign in to comment.