forked from mirrors/org-mode
org-eww: Small refactoring
* contrib/lisp/org-eww.el (org-eww-store-link): (org-eww-copy-for-org-mode): (eww-mode-hook): Small refactoring.
This commit is contained in:
parent
0abf6ee28b
commit
5e224bb2ef
|
@ -61,7 +61,7 @@
|
||||||
:description (if (< emacs-major-version 25)
|
:description (if (< emacs-major-version 25)
|
||||||
(or eww-current-title eww-current-url)
|
(or eww-current-title eww-current-url)
|
||||||
(or (plist-get eww-data :title)
|
(or (plist-get eww-data :title)
|
||||||
(eww-current-url))))))
|
(eww-current-url))))))
|
||||||
|
|
||||||
|
|
||||||
;; Some auxiliary functions concerning links in eww buffers
|
;; Some auxiliary functions concerning links in eww buffers
|
||||||
|
@ -101,29 +101,29 @@ the structure of the Org file."
|
||||||
(setq transform-start (region-beginning))
|
(setq transform-start (region-beginning))
|
||||||
(setq transform-end (region-end))
|
(setq transform-end (region-end))
|
||||||
;; Deactivate mark if current mark is activate.
|
;; Deactivate mark if current mark is activate.
|
||||||
(if (fboundp 'deactivate-mark) (deactivate-mark)))
|
(when (fboundp 'deactivate-mark) (deactivate-mark)))
|
||||||
(message "Transforming links...")
|
(message "Transforming links...")
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char transform-start)
|
(goto-char transform-start)
|
||||||
(while (and (not out-bound) ; still inside region to copy
|
(while (and (not out-bound) ; still inside region to copy
|
||||||
(org-eww-has-further-url-property-change-p)) ; there is a next link
|
(org-eww-has-further-url-property-change-p)) ; there is a next link
|
||||||
;; store current point before jump next anchor
|
;; Store current point before jump next anchor.
|
||||||
(setq temp-position (point))
|
(setq temp-position (point))
|
||||||
;; move to next anchor when current point is not at anchor
|
;; Move to next anchor when current point is not at anchor.
|
||||||
(or (org-eww-url-below-point)
|
(or (org-eww-url-below-point)
|
||||||
(org-eww-goto-next-url-property-change))
|
(org-eww-goto-next-url-property-change))
|
||||||
(assert (org-eww-url-below-point) t
|
(assert (org-eww-url-below-point) t
|
||||||
"program logic error: point must have an url below but it hasn't")
|
"program logic error: point must have an url below but it hasn't")
|
||||||
(if (<= (point) transform-end) ; if point is inside transform bound
|
(if (<= (point) transform-end) ; if point is inside transform bound
|
||||||
(progn
|
(progn
|
||||||
;; get content between two links.
|
;; Get content between two links.
|
||||||
(if (< temp-position (point))
|
(when (< temp-position (point))
|
||||||
(setq return-content (concat return-content
|
(setq return-content (concat return-content
|
||||||
(buffer-substring
|
(buffer-substring
|
||||||
temp-position (point)))))
|
temp-position (point)))))
|
||||||
;; get link location at current point.
|
;; Get link location at current point.
|
||||||
(setq link-location (org-eww-url-below-point))
|
(setq link-location (org-eww-url-below-point))
|
||||||
;; get link title at current point.
|
;; Get link title at current point.
|
||||||
(setq link-title
|
(setq link-title
|
||||||
(buffer-substring
|
(buffer-substring
|
||||||
(point)
|
(point)
|
||||||
|
@ -132,23 +132,17 @@ the structure of the Org file."
|
||||||
(setq return-content (concat return-content
|
(setq return-content (concat return-content
|
||||||
(org-make-link-string
|
(org-make-link-string
|
||||||
link-location link-title))))
|
link-location link-title))))
|
||||||
(goto-char temp-position) ; reset point before jump next anchor
|
(goto-char temp-position) ; reset point before jump next anchor
|
||||||
(setq out-bound t) ; for break out `while' loop
|
(setq out-bound t) ; for break out `while' loop
|
||||||
))
|
))
|
||||||
;; add the rest until end of the region to be copied
|
;; Add the rest until end of the region to be copied.
|
||||||
(if (< (point) transform-end)
|
(when (< (point) transform-end)
|
||||||
(setq return-content
|
(setq return-content
|
||||||
(concat return-content
|
(concat return-content
|
||||||
(buffer-substring (point) transform-end))))
|
(buffer-substring (point) transform-end))))
|
||||||
;; quote lines starting with *
|
;; Quote lines starting with *.
|
||||||
(org-kill-new
|
(org-kill-new (replace-regexp-in-string "^\\*" ",*" return-content))
|
||||||
(with-temp-buffer
|
(message "Transforming links...done, use C-y to insert text into Org mode file"))))
|
||||||
(insert return-content)
|
|
||||||
(goto-char 0)
|
|
||||||
(while (re-search-forward "^\*" nil t)
|
|
||||||
(replace-match ",*"))
|
|
||||||
(buffer-string)))
|
|
||||||
(message "Transforming links...done, use C-y to insert text into Org-mode file"))))
|
|
||||||
|
|
||||||
|
|
||||||
;; Additional keys for eww-mode
|
;; Additional keys for eww-mode
|
||||||
|
@ -161,9 +155,7 @@ the structure of the Org file."
|
||||||
(keymapp eww-mode-map)) ; eww is already up.
|
(keymapp eww-mode-map)) ; eww is already up.
|
||||||
(org-eww-extend-eww-keymap))
|
(org-eww-extend-eww-keymap))
|
||||||
|
|
||||||
(add-hook
|
(add-hook 'eww-mode-hook #'org-eww-extend-eww-keymap)
|
||||||
'eww-mode-hook
|
|
||||||
(lambda () (org-eww-extend-eww-keymap)))
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'org-eww)
|
(provide 'org-eww)
|
||||||
|
|
Loading…
Reference in New Issue