Org Mode 的 Agenda 里面按 F
有跟随功能,类似 follow-mode
.
我想给 google-translate
实现类似的功能。谷歌翻译的网页翻页有这个功能,很方便双语对比。
这里是 org-agenda-follow 的实现
(defun org-agenda-follow-mode ()
"Toggle follow mode in an agenda buffer."
(interactive)
(unless org-agenda-follow-mode
(setq org-agenda-pre-follow-window-conf
(current-window-configuration)))
(setq org-agenda-follow-mode (not org-agenda-follow-mode))
(unless org-agenda-follow-mode
(set-window-configuration org-agenda-pre-follow-window-conf))
(org-agenda-set-mode-name)
(org-agenda-do-context-action) ; (1)
(message "Follow mode is %s"
(if org-agenda-follow-mode "on" "off")))
(defun org-agenda-do-context-action ()
"Show outline path and, maybe, follow mode window."
(let ((m (org-get-at-bol 'org-marker)))
(when (and (markerp m) (marker-buffer m))
(and org-agenda-follow-mode
(if org-agenda-follow-indirect
(org-agenda-tree-to-indirect-buffer nil) ; (2)
(org-agenda-show)))
(and org-agenda-show-outline-path
(org-with-point-at m (org-display-outline-path t))))))
(defun org-agenda-tree-to-indirect-buffer (arg)
"Show the subtree corresponding to the current entry in an indirect buffer.
This calls the command `org-tree-to-indirect-buffer' from the original buffer.
With a numerical prefix ARG, go up to this level and then take that tree.
With a negative numeric ARG, go up by this number of levels.
With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
i.e. don't use
the dedicated frame."
(interactive "P")
(if current-prefix-arg
(org-agenda-do-tree-to-indirect-buffer arg)
(let ((agenda-buffer (buffer-name))
(agenda-window (selected-window))
(indirect-window
(and org-last-indirect-buffer
(get-buffer-window org-last-indirect-buffer))))
(save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
(unless (or (eq org-indirect-buffer-display 'new-frame)
(eq org-indirect-buffer-display 'dedicated-frame))
(unwind-protect
(unless (and indirect-window (window-live-p indirect-window))
(setq indirect-window (split-window agenda-window)))
(and indirect-window (select-window indirect-window))
(switch-to-buffer org-last-indirect-buffer :norecord)
(fit-window-to-buffer indirect-window)))
(select-window (get-buffer-window agenda-buffer))
(setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
这里是我的实现思路
- [ ] how to separate translation source text?
- [ ] use markers
- [ ] use text-properties as markers
- [ ] separate text with sentences as unit
- [ ] how to mark sentence beginning and end?
- [ ] how to add text-property on sentence unit?
- [ ] what text-property key-value to assign?
- [ ] a unique value of key ~'google-translate-sentence~
- [ ] use number or hash value?
- [ ] a unique value of key ~'google-translate-sentence~
- [ ] insert text-property markers in source text before translation
- [ ] how to add corresponding text-property to translated text? (question)
- [ ] google-translate on sentence by one sentence, then combine results into one?
- [ ] This is not efficient
- [ ] check out how google web page translate implement this?
- [ ] google-translate on sentence by one sentence, then combine results into one?
- [ ] follow-mode follows those text-property markers between source buffer and translated buffer
- [ ] also highlight follow part text with different highlight background color
- [ ] add detect markers function to ~post-command-hook~
- [ ] separate text with sentences as unit
- [ ] use text-properties as markers
- [ ] use markers
翻译成中文很麻烦,写Elisp的大多都能看懂这个英文,就不特意再翻译一下了。
现在的困难在标记 (question)
的地方