Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sachac user files #19

Merged
merged 10 commits into from
Jan 16, 2024
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ jobs:
strategy:
matrix:
emacs_version:
- 24.4
- 25.3
- 26.3
- 27.1
- 28.1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ all: check
check: compile test

compile:
${EMACS} -Q --batch -L . --eval "(setq byte-compile-error-on-warn t)" -f batch-byte-compile elisp-demos.el
${EMACS} -Q --batch -L . --eval "(setq byte-compile-error-on-warn nil)" -f batch-byte-compile elisp-demos.el

test:
${EMACS} -Q --batch -L . -l elisp-demos-tests -f ert-run-tests-batch-and-exit
Expand Down
57 changes: 35 additions & 22 deletions elisp-demos.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Homepage: https://github.com/xuchunyang/elisp-demos
;; Keywords: lisp, docs
;; Version: 2024.01.16
;; Package-Requires: ((emacs "24.4"))
;; Package-Requires: ((emacs "26.3"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -27,11 +27,12 @@

;;; Code:

(eval-when-compile (require 'cl-lib))
(require 'cl-lib)
(require 'subr-x)
(require 'org)

(defconst elisp-demos--load-dir (file-name-directory
(or load-file-name buffer-file-name)))
(or load-file-name buffer-file-name)))

(defconst elisp-demos--elisp-demos.org (expand-file-name
"elisp-demos.org"
Expand All @@ -50,14 +51,18 @@ If set, new notes are added to the first file in this list."
(with-temp-buffer
(insert-file-contents file)
(delay-mode-hooks (org-mode))
(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)))
results)))))
(let ((pos (org-find-exact-headline-in-buffer (symbol-name symbol))))
(when pos
(goto-char pos)
(org-end-of-meta-data)
(push (propertize
(string-trim
(buffer-substring-no-properties
(point)
(org-end-of-subtree)))
'file file
'pos (marker-position pos))
results))))))
(when results
(string-join (nreverse results) "\n\n"))))

Expand All @@ -80,10 +85,7 @@ If set, new notes are added to the first file in this list."
(delay-mode-hooks (org-mode))
(while (re-search-forward "^\\* +\\(.+\\)$" nil t)
(push (org-entry-get (point) "ITEM") symbols))))
(mapcar 'intern (sort (seq-uniq symbols) #'string<))))

(declare-function org-show-entry "org" ())
(declare-function org-insert-heading "org" (&optional arg invisible-ok top))
(mapcar 'intern (sort (cl-delete-duplicates symbols :test #'eq) #'string<))))

(defun elisp-demos-find-demo (symbol)
"Find the demo of the SYMBOL."
Expand All @@ -107,6 +109,9 @@ If set, new notes are added to the first file in this list."
(when pos
(goto-char pos)
(org-show-entry)
(if (fboundp 'pop-to-buffer-same-window)
(pop-to-buffer-same-window (current-buffer))
(pop-to-buffer (current-buffer)))
(throw 'found (point)))))))
t)

Expand Down Expand Up @@ -165,11 +170,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 @@ -223,14 +227,23 @@ If set, new notes are added to the first file in this list."
'keymap elisp-demos-help-keymap)
"\n\n")
"")
(buttonize "[Add]" #'elisp-demos-add-demo helpful--sym)
(if (fboundp 'buttonize)
(buttonize "[Add]" #'elisp-demos-add-demo helpful--sym)
(insert-text-button
"[Add]"
'face 'link
'action (lambda (_button)
(elisp-demos-add-demo helpful--sym))))
"\n\n"))))))

;;;###autoload
(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