[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-translate d672d8c 08/19: [org-translate] Rename ogt
From: |
Stefan Monnier |
Subject: |
[elpa] externals/org-translate d672d8c 08/19: [org-translate] Rename ogt-add-glossary-item: ogt-new-glossary-term |
Date: |
Tue, 1 Dec 2020 16:34:22 -0500 (EST) |
branch: externals/org-translate
commit d672d8ced1aaf58b817c92bfe7e867151097b8b9
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>
[org-translate] Rename ogt-add-glossary-item: ogt-new-glossary-term
* packages/org-translate/org-translate.el (ogt-new-glossary-term): Fix
bug in adding the very first glossary item. When finding other
instances of the term, anticipate them being split across lines.
(org-translate-mode-map): Provide binding for both adding new term,
and inserting translation.
---
org-translate.el | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/org-translate.el b/org-translate.el
index 9d59cae..e882b4f 100644
--- a/org-translate.el
+++ b/org-translate.el
@@ -97,13 +97,12 @@
;; translated a term previously, and offers these for completion on
;; inserting a new translation.
-;; To create a new glossary term, use "M-x ogt-add-glossary-item". If
-;; you've marked text in the source buffer, this will become the new
-;; term, otherwise you'll be prompted to enter the string. This
-;; command will attempt to turn all instances of this term in the
-;; source text into a link.
+;; To create a new glossary term, use "C-M-y". If you've marked text
+;; in the source buffer, this will become the new term, otherwise
+;; you'll be prompted to enter the string. This command will attempt
+;; to turn all instances of this term in the source text into a link.
-;; In the translation text, use "C-M-y"
+;; In the translation text, use "C-M-;"
;; (`ogt-insert-glossary-translation') to add a translation. The mode
;; will attempt to guess which term you're adding, and suggest
;; previous translations for that term.
@@ -310,7 +309,8 @@ By default, just remove it."
(define-key map (kbd "C-M-b") #'ogt-backward-segment)
(define-key map (kbd "C-M-n") #'ogt-new-segment)
(define-key map (kbd "C-M-t") #'ogt-update-source-location)
- (define-key map (kbd "C-M-y") #'ogt-insert-glossary-translation)
+ (define-key map (kbd "C-M-y") #'ogt-new-glossary-term)
+ (define-key map (kbd "C-M-;") #'ogt-insert-glossary-translation)
map))
(define-minor-mode org-translate-mode
@@ -643,7 +643,7 @@ the next one."
(recenter 10))
(ogt-update-source-location)))
-(defun ogt-add-glossary-item (string)
+(defun ogt-new-glossary-term (string)
"Add STRING as an item in the glossary.
If the region is active, it will be used as STRING. Otherwise,
prompt the user for STRING."
@@ -655,18 +655,24 @@ prompt the user for STRING."
(read-string "Glossary term: "))))
(save-excursion
(ogt-goto-heading 'glossary)
- (org-goto-first-child)
- (org-insert-heading-respect-content)
+ (if (org-goto-first-child)
+ (org-insert-heading-respect-content)
+ (end-of-line)
+ (org-insert-subheading 1))
(insert string)
- (let ((id (org-id-get-create)))
+ (let ((id (org-id-get-create))
+ ;; STRING might be broken across lines. What do we do about
+ ;; Chinese, with no word separators?
+ (doctored (replace-regexp-in-string
+ "[[:blank:]]+" "[[:space:]\n]+"
+ string)))
(ogt-goto-heading 'source)
(save-restriction
(org-narrow-to-subtree)
- ;; TODO: `string' highly likely to be broken over newlines.
- (while (re-search-forward string nil t)
+ (while (re-search-forward doctored nil t)
(replace-match (format "[[trans:%s][%s]]" id string))))
(push string (alist-get 'source (gethash id ogt-glossary-table)))))
- (message "Added %s as a glossary item" string))
+ (message "Added %s as a glossary term" string))
(defun ogt-insert-glossary-translation ()
"Insert a likely translation of the next glossary item."
- [elpa] externals/org-translate 8fe738a 05/19: [org-translate] Segment both source and translation trees, (continued)
- [elpa] externals/org-translate 8fe738a 05/19: [org-translate] Segment both source and translation trees, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate e60252b 07/19: [org-translate] Be stricter at startup, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 3024d22 03/19: [org-translate] Remove extraneous Author header, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 380ab9e 10/19: [org-translate] Fix bug in ogt-hightlight-source-segment, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate c3600f4 14/19: [org-translate] Remove ogt-follow-link, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 9539f01 11/19: [org-translate] Add keymap for translation links, plus occur command, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 94f9307 15/19: [org-translate] New command ogt-term-display-translations, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 7b31f0a 04/19: [org-translate] Require 'ox library, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate fbd9d57 01/19: [org-translate] Add version 0 of org-translate, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate fecfa31 06/19: [org-translate] Improve documentation, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate d672d8c 08/19: [org-translate] Rename ogt-add-glossary-item: ogt-new-glossary-term,
Stefan Monnier <=
- [elpa] externals/org-translate 1630bad 19/19: * .gitignore: New file, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate f7bcba6 09/19: [org-translate] Allow ogt-insert-glossary-translation to prompt, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 8d6c684 12/19: [org-translate] Release version 0.1, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 1a7368c 13/19: [org-translate] Fix bum link following, bump to 0.1.1, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate b67b45c 16/19: [org-translate] Do a better job of reporting errors at startup, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate 50b870c 17/19: [org-translate] Improve segmentation of subtree headings, bump 0.1.2, Stefan Monnier, 2020/12/01
- [elpa] externals/org-translate d451901 18/19: [org-translate] Fix bum logic in finding the end of a segment, Stefan Monnier, 2020/12/01