branch: externals/org-transclusion commit e4f96e114bfb782a7d0c9a6f7bc095b78e6ee4ea Merge: 1146293107 b3e59a7b0a Author: Noboru Ota <m...@nobiot.com> Commit: Noboru Ota <m...@nobiot.com>
Merge branch 'dev/feature--things-at-point' --- org-transclusion-src-lines.el | 35 +++++++++++++++++++++++++----- org-transclusion.el | 44 +++++++++++++++----------------------- test/things-at-point-dir/baz.el | 10 +++++++++ test/things-at-point-dir/story.txt | 7 ++++++ test/things-at-point.org | 27 +++++++++++++++++++++++ 5 files changed, 91 insertions(+), 32 deletions(-) diff --git a/org-transclusion-src-lines.el b/org-transclusion-src-lines.el index 97fdbf3583..4d431e794b 100644 --- a/org-transclusion-src-lines.el +++ b/org-transclusion-src-lines.el @@ -17,7 +17,7 @@ ;; Author: Noboru Ota <m...@nobiot.com> ;; Created: 24 May 2021 -;; Last modified: 28 March 2023 +;; Last modified: 08 May 2023 ;;; Commentary: ;; This is an extension to `org-transclusion'. When active, it adds features @@ -32,8 +32,6 @@ (declare-function org-transclusion-org-file-p "org-transclusion") -(declare-function org-transclusion-keyword-value-thing-at-point - "org-transclusion") ;;;; Setting up the extension ;; Add a new transclusion type @@ -55,7 +53,8 @@ #'org-transclusion-keyword-plist-to-string-src-lines) ;; Transclusion content formating -;; Not needed. Default works for text files. +(add-hook 'org-transclusion-content-format-functions + #'org-transclusion-content-format-src-lines) ;; Open source buffer (add-hook 'org-transclusion-open-source-marker-functions @@ -211,7 +210,7 @@ for the range works." (format "#+begin_src %s" src-lang) (when rest (format " %s" rest)) "\n" - (org-transclusion--ensure-newline src-content) + (org-transclusion-ensure-newline src-content) "#+end_src\n"))))) ;; Return the payload either modified or unmodified payload)) @@ -305,5 +304,31 @@ for non-Org text files including program source files." (- (region-end) newline-offset)))) (cons src-ov tc-ov)))) +;;; Thing-at-point +(defun org-transclusion-keyword-value-thing-at-point (string) + "It is a utility function used converting a keyword STRING to plist. +It is meant to be used by `org-transclusion-get-string-to-plist'. +It needs to be set in `org-transclusion-get-keyword-values-hook'. +Double qutations are optional :thing-at-point \"sexp\". The regex should +match any valid elisp symbol (but please don't quote it)." + (when (string-match ":thing-at-point \\([[:alnum:][:punct:]]+\\)" string) + (list :thing-at-point (org-strip-quotes (match-string 1 string))))) + +(defun org-transclusion-content-format-src-lines (type content indent) + "Format text CONTENT from source before transcluding. +Return content modified (or unmodified, if not applicable). + +This is the default one. It only returns the content as is. + +INDENT is the number of current indentation of the #+transclude." + (when (org-transclusion-src-lines-p type) + (let ((content (org-transclusion-ensure-newline content))) + (org-transclusion-content-format type content indent)))) + +(defun org-transclusion-ensure-newline (str) + (if (not (string-suffix-p "\n" str)) + (concat str "\n") + str)) + (provide 'org-transclusion-src-lines) ;;; org-transclusion-src-lines.el ends here diff --git a/org-transclusion.el b/org-transclusion.el index 9ceaaa004f..86c61cc83f 100644 --- a/org-transclusion.el +++ b/org-transclusion.el @@ -17,7 +17,7 @@ ;; Author: Noboru Ota <m...@nobiot.com> ;; Created: 10 October 2020 -;; Last modified: 28 March 2023 +;; Last modified: 08 May 2023 ;; URL: https://github.com/nobiot/org-transclusion ;; Keywords: org-mode, transclusion, writing @@ -201,7 +201,6 @@ that consists of the following properties: (defvar org-transclusion-keyword-value-functions '(org-transclusion-keyword-value-link - org-transclusion-keyword-value-thing-at-point org-transclusion-keyword-value-level org-transclusion-keyword-value-disable-auto org-transclusion-keyword-value-only-contents @@ -800,15 +799,6 @@ It is meant to be used by (user-error "Error. Link in #+transclude is mandatory at %d" (point)) nil)) -(defun org-transclusion-keyword-value-thing-at-point (string) - "It is a utility function used converting a keyword STRING to plist. -It is meant to be used by `org-transclusion-get-string-to-plist'. -It needs to be set in `org-transclusion-get-keyword-values-hook'. -Double qutations are optional :thing-at-point \"sexp\". The regex should -match any valid elisp symbol (but please don't quote it)." - (when (string-match ":thing-at-point \\([[:alnum:][:punct:]]+\\)" string) - (list :thing-at-point (org-strip-quotes (match-string 1 string))))) - (defun org-transclusion-keyword-value-disable-auto (string) "It is a utility function used converting a keyword STRING to plist. It is meant to be used by `org-transclusion-get-string-to-plist'. @@ -1068,22 +1058,22 @@ This function is the default for org-transclusion-type (TYPE) \"org-*\". Currently it only re-aligns table with links in the content." (when (org-transclusion-type-is-org type) - (with-temp-buffer - (let ((org-inhibit-startup t)) - (delay-mode-hooks (org-mode)) - (insert content) - ;; Fix table alignment - (let ((point (point-min))) - (while point - (goto-char (1+ point)) - (when (org-at-table-p) - (org-table-align) - (goto-char (org-table-end))) - (setq point (search-forward "|" (point-max) t)))) - ;; Fix indentation when `org-adapt-indentation' is non-nil - (org-indent-region (point-min) (point-max)) - ;; Return the temp-buffer's string - (buffer-string))))) + (with-temp-buffer + (let ((org-inhibit-startup t)) + (delay-mode-hooks (org-mode)) + (insert content) + ;; Fix table alignment + (let ((point (point-min))) + (while point + (goto-char (1+ point)) + (when (org-at-table-p) + (org-table-align) + (goto-char (org-table-end))) + (setq point (search-forward "|" (point-max) t)))) + ;; Fix indentation when `org-adapt-indentation' is non-nil + (org-indent-region (point-min) (point-max)) + ;; Return the temp-buffer's string + (buffer-string))))) (defun org-transclusion-content-format (_type content indent) "Format text CONTENT from source before transcluding. diff --git a/test/things-at-point-dir/baz.el b/test/things-at-point-dir/baz.el new file mode 100644 index 0000000000..f0546a38dc --- /dev/null +++ b/test/things-at-point-dir/baz.el @@ -0,0 +1,10 @@ +(defun bar (arg) + "Documentation for bar" + arg) + + +;; Comments +(defun foo () + "Documentation for this function." + (bar (let ((fuzz (buzz))) ;<id:1234567890> + (baz fuzz))) diff --git a/test/things-at-point-dir/story.txt b/test/things-at-point-dir/story.txt new file mode 100644 index 0000000000..3c9521de54 --- /dev/null +++ b/test/things-at-point-dir/story.txt @@ -0,0 +1,7 @@ +This is a story + +Once upon a time. This paragraph should be transcluded. This is a story. +And if I have a hard line break, I belive this line is still part of +the paragraph as defined by ... thing-at-point I think. + +This is a new paragraph and should not be included. diff --git a/test/things-at-point.org b/test/things-at-point.org new file mode 100644 index 0000000000..3fd9568b64 --- /dev/null +++ b/test/things-at-point.org @@ -0,0 +1,27 @@ + What are the allowed (intended?) or tested "things"? + +I've briefly tested these: + + word + symbol + line (redundant, since we already have :lines) + +forward-thing is the function used for selecting multiple things. Some gotchas from some of the less common things could stem from this not handing them as expected. + +I expect these will be more common: + + sentence + paragraph + defun + sexp + list + +#+transclude: [[./things-at-point-dir/story.txt::Once upon a time][story]] :thing-at-point paragraph + +#+transclude: [[./things-at-point-dir/story.txt::Once upon a time][story]] :thing-at-point sentence + +#+transclude: [[./things-at-point-dir/baz.el::id:1234567890][barz-baz-fuzz]] :src elisp + +#+transclude: [[./things-at-point-dir/baz.el::foo][barz-baz-fuzz]] :src elisp :thing-at-point sexp + +#+transclude: [[./things-at-point-dir/baz.el::id:1234567890][barz-baz-fuzz]] :src elisp :thing-at-point defun