Skip to content

Commit db09159

Browse files
authored
Merge pull request #249 from tarsiiformes/tidy
Various minor cleanup
2 parents 1edfced + 787a845 commit db09159

File tree

1 file changed

+64
-57
lines changed

1 file changed

+64
-57
lines changed

org-transclusion.el

+64-57
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ Intended for :set property for `customize'."
5959
(when (featurep 'org-transclusion)
6060
(org-transclusion-load-extensions-maybe 'force)))
6161

62-
(defcustom org-transclusion-extensions '(org-transclusion-src-lines org-transclusion-font-lock)
62+
(defcustom org-transclusion-extensions
63+
'(org-transclusion-src-lines org-transclusion-font-lock)
6364
"Extensions to be loaded with org-transclusion.el."
6465
:set #'org-transclusion-set-extensions
6566
:type
6667
'(set :greedy t
67-
(const :tag "src-lines: Add :src and :lines for non-Org files" org-transclusion-src-lines)
68-
(const :tag "font-lock: Add font-lock for Org-transclusion" org-transclusion-font-lock)
69-
70-
(const :tag "indent-mode: Support org-indent-mode" org-transclusion-indent-mode)
68+
(const :tag "src-lines: Add :src and :lines for non-Org files"
69+
org-transclusion-src-lines)
70+
(const :tag "font-lock: Add font-lock for Org-transclusion"
71+
org-transclusion-font-lock)
72+
(const :tag "indent-mode: Support org-indent-mode"
73+
org-transclusion-indent-mode)
7174
(const :tag "html: Transclude HTML converted to Org with Pandoc"
7275
org-transclusion-html)
7376
(repeat :tag "Other packages" :inline t (symbol :tag "Package"))))
@@ -379,14 +382,16 @@ transclusion keyword."
379382
(interactive "P")
380383
(let* ((context (org-element-lineage
381384
(org-element-context)'(link) t))
382-
(auto-transclude-p (if (or (not arg) (numberp arg)) org-transclusion-mode
385+
(auto-transclude-p (if (or (not arg) (numberp arg))
386+
org-transclusion-mode
383387
;; if `universal-argument' is passed,
384388
;; reverse nil/t when
385-
(if org-transclusion-mode nil t))))
389+
(not org-transclusion-mode))))
386390
(let* ((contents-beg (org-element-property :contents-begin context))
387391
(contents-end (org-element-property :contents-end context))
388-
(contents (when contents-beg
389-
(buffer-substring-no-properties contents-beg contents-end)))
392+
(contents (and contents-beg
393+
(buffer-substring-no-properties contents-beg
394+
contents-end)))
390395
(link (org-element-link-interpreter context contents)))
391396
(save-excursion
392397
(org-transclusion-search-or-add-next-empty-line)
@@ -473,11 +478,10 @@ hooks in `org-transclusion-add-functions'."
473478
(eq src-content nil))
474479
;; Keep going with program when no content `org-transclusion-add-all'
475480
;; should move to the next transclusion
476-
(progn (message
477-
(format
478-
"No content found with \"%s\". Check the link at point %d, line %d"
479-
(org-element-property :raw-link link) (point) (org-current-line))
480-
nil))
481+
(prog1 nil
482+
(message
483+
"No content found with \"%s\". Check the link at point %d, line %d"
484+
(org-element-property :raw-link link) (point) (org-current-line)))
481485
(let ((beg (line-beginning-position))
482486
(end))
483487
(org-transclusion-with-inhibit-read-only
@@ -524,7 +528,8 @@ the rest of the buffer unchanged."
524528
(with-demoted-errors
525529
"Not transcluded. Continue to next: %S"
526530
(when (org-transclusion-add)
527-
(message (format "Transcluded at point %d, line %d" (point) (org-current-line))))))))
531+
(message "Transcluded at point %d, line %d"
532+
(point) (org-current-line)))))))
528533
(goto-char marker)
529534
(move-marker marker nil) ; point nowhere for GC
530535
t)))
@@ -533,10 +538,10 @@ the rest of the buffer unchanged."
533538
"Remove transcluded text at point.
534539
When success, return the beginning point of the keyword re-inserted."
535540
(interactive)
536-
(if-let* ((beg (marker-position (get-char-property (point)
537-
'org-transclusion-beg-mkr)))
538-
(end (marker-position (get-char-property (point)
539-
'org-transclusion-end-mkr)))
541+
(if-let* ((beg (marker-position
542+
(get-char-property (point) 'org-transclusion-beg-mkr)))
543+
(end (marker-position
544+
(get-char-property (point) 'org-transclusion-end-mkr)))
540545
(keyword-plist (get-char-property (point)
541546
'org-transclusion-orig-keyword))
542547
(indent (plist-get keyword-plist :current-indentation))
@@ -795,9 +800,10 @@ set in `before-save-hook'. It also move the point back to
795800
(move-marker p nil)
796801
(setq do-count (1+ do-count))
797802
(when (> do-count do-length)
798-
(error "org-transclusion: Aborting. You may be in an infinite loop"))))
799-
;; After save and adding all transclusions, the modified flag should be
800-
;; set to nil
803+
(error
804+
"org-transclusion: Aborting. You may be in an infinite loop"))))
805+
;; After save and adding all transclusions, the modified flag should
806+
;; be set to nil.
801807
(restore-buffer-modified-p nil)
802808
(when org-transclusion-remember-point
803809
(goto-char org-transclusion-remember-point))))
@@ -973,8 +979,8 @@ Return nil if not found."
973979
(if mkr
974980
(append payload (org-transclusion-content-org-marker mkr plist))
975981
(message
976-
(format "No transclusion done for this ID. Ensure it works at point %d, line %d"
977-
(point) (org-current-line)))
982+
"No transclusion done for this ID. Ensure it works at point %d, line %d"
983+
(point) (org-current-line))
978984
nil))))
979985

980986
(defun org-transclusion-add-org-file (link plist)
@@ -995,7 +1001,8 @@ Return nil if not found."
9951001
;;-----------------------------------------------------------------------------
9961002
;;;; Functions for inserting content
9971003

998-
(defun org-transclusion-content-insert (keyword-values type content sbuf sbeg send copy)
1004+
(defun org-transclusion-content-insert ( keyword-values type content
1005+
sbuf sbeg send copy)
9991006
"Insert CONTENT at point and put source overlay in SBUF.
10001007
Return t when successful.
10011008
@@ -1052,28 +1059,23 @@ based on the following arguments:
10521059
(setq end (point))
10531060
(setq end-mkr (set-marker (make-marker) end))
10541061
(unless copy
1055-
(add-text-properties beg end
1056-
`(local-map ,org-transclusion-map
1057-
read-only t
1058-
front-sticky t
1059-
;; rear-nonticky seems better for
1060-
;; src-lines to add "#+result" after C-c
1061-
;; C-c
1062-
rear-nonsticky t
1063-
org-transclusion-type ,type
1064-
org-transclusion-beg-mkr
1065-
,beg-mkr
1066-
org-transclusion-end-mkr
1067-
,end-mkr
1068-
org-transclusion-pair
1069-
,tc-pair
1070-
org-transclusion-orig-keyword
1071-
,keyword-values
1072-
;; TODO Fringe is not supported for terminal
1073-
line-prefix
1074-
,(org-transclusion-propertize-transclusion)
1075-
wrap-prefix
1076-
,(org-transclusion-propertize-transclusion)))
1062+
(add-text-properties
1063+
beg end
1064+
`( local-map ,org-transclusion-map
1065+
read-only t
1066+
front-sticky t
1067+
;; rear-nonticky seems better for
1068+
;; src-lines to add "#+result" after C-c
1069+
;; C-c
1070+
rear-nonsticky t
1071+
org-transclusion-type ,type
1072+
org-transclusion-beg-mkr ,beg-mkr
1073+
org-transclusion-end-mkr ,end-mkr
1074+
org-transclusion-pair ,tc-pair
1075+
org-transclusion-orig-keyword ,keyword-values
1076+
;; TODO Fringe is not supported for terminal
1077+
line-prefix ,(org-transclusion-propertize-transclusion)
1078+
wrap-prefix ,(org-transclusion-propertize-transclusion)))
10771079
;; Put the transclusion overlay
10781080
(let ((ov-tc (text-clone-make-overlay beg end)))
10791081
(overlay-put ov-tc 'evaporate t)
@@ -1210,7 +1212,8 @@ property controls the filter applied to the transclusion."
12101212
;; For dedicated target, we want to get the parent paragraph,
12111213
;; rather than the target itself
12121214
(when (and (string= "target" type)
1213-
(string= "paragraph" (org-element-type (org-element-property :parent el))))
1215+
(string= "paragraph"
1216+
(org-element-type (org-element-property :parent el))))
12141217
(setq el (org-element-property :parent el)))
12151218
(let ((beg (org-element-property :begin el))
12161219
(end (org-element-property :end el))
@@ -1243,7 +1246,8 @@ property controls the filter applied to the transclusion."
12431246

12441247
;; Expand file names in all the links
12451248
(when expand-links
1246-
(org-element-map obj 'link #'org-transclusion-content-filter-expand-links))
1249+
(org-element-map obj 'link
1250+
#'org-transclusion-content-filter-expand-links))
12471251

12481252
(list :src-content (org-element-interpret-data obj)
12491253
:src-buf (current-buffer)
@@ -1401,12 +1405,14 @@ Case 2. #+transclude inside another transclusion"
14011405
;; Case 1. Element at point is NOT #+transclude:
14021406
((not (and (string-equal "keyword" (org-element-type elm))
14031407
(string-equal "TRANSCLUDE" (org-element-property :key elm))))
1404-
(user-error (format "Not at a transclude keyword or transclusion in a block at point %d, line %d"
1405-
(point) (org-current-line))))
1408+
(user-error
1409+
"Not at a transclude keyword or transclusion in a block at point %d, line %d"
1410+
(point) (org-current-line)))
14061411
;; Case 2. #+transclude inside another transclusion
14071412
((org-transclusion-within-transclusion-p)
1408-
(user-error (format "Cannot transclude in another transclusion at point %d, line %d"
1409-
(point) (org-current-line))))
1413+
(user-error
1414+
"Cannot transclude in another transclusion at point %d, line %d"
1415+
(point) (org-current-line)))
14101416
(t
14111417
t))))
14121418

@@ -1431,8 +1437,9 @@ https://github.com/nobiot/org-transclusion/issues/177."
14311437
(eol (line-end-position))
14321438
(case-fold-search t))
14331439
(goto-char bol)
1434-
(when (and (re-search-forward "^[[:blank:]]*#\\+\\(\\S-*\\)" eol :noerror)
1435-
(string-equal-ignore-case "transclude" (match-string-no-properties 1)))
1440+
(when (and (re-search-forward "^[[:blank:]]*#\\+\\(\\S-*\\)" eol t)
1441+
(string-equal-ignore-case
1442+
"transclude" (match-string-no-properties 1)))
14361443
(replace-match
14371444
(concat (match-string-no-properties 1) ":")
14381445
t nil nil 1)
@@ -1568,12 +1575,12 @@ original buffer. This is required especially when transclusion is
15681575
for a paragraph, which can be right next to another paragraph
15691576
without a blank space; thus, subsumed by the surrounding
15701577
paragraph."
1571-
(let* ((beg (or (when-let ((m (get-char-property (point)
1578+
(let* ((beg (or (and-let* ((m (get-char-property (point)
15721579
'org-transclusion-beg-mkr)))
15731580
(marker-position m))
15741581
(overlay-start (get-char-property (point)
15751582
'org-transclusion-pair))))
1576-
(end (or (when-let ((m (get-char-property (point)
1583+
(end (or (and-let* ((m (get-char-property (point)
15771584
'org-transclusion-end-mkr)))
15781585
(marker-position m))
15791586
(overlay-end (get-char-property (point)

0 commit comments

Comments
 (0)