diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6b1d070..aba1933 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,8 +8,6 @@ jobs: strategy: matrix: emacs_version: - - 24.4 - - 25.3 - 26.3 - 27.1 - 28.1 diff --git a/Makefile b/Makefile index abedfbe..d39f5a4 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/elisp-demos.el b/elisp-demos.el index 0d74254..1d49eee 100644 --- a/elisp-demos.el +++ b/elisp-demos.el @@ -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 @@ -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" @@ -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")))) @@ -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." @@ -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) @@ -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))) @@ -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