[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] Partial word emphasis suggestion
From: |
cinsky |
Subject: |
[O] Partial word emphasis suggestion |
Date: |
Sun, 02 Mar 2014 10:04:57 +0900 |
Dear Org-mode members,
A couple of years ago, I asked how to emphasis partial word
(e.g. =no-emphasis=on-subword=) without blank character, and someone
pointed out this link:
http://thread.gmane.org/gmane.emacs.orgmode/46197/focus=46263
Basically, it suggest to add unicode "word joiner" character (\u2060)
in `org-emphasis-regexp-components' like this:
(org-set-emph-re 'org-emphasis-regexp-components
'(" \t('\"{\\\u2060"
"- \t.,:!?;'\")}\\\u2060"
" \t\r\n,\"'"
"." 1)))
Some human languages (Korean, including CJK) uses lots of postfix
components, so we need a partial word emphasis a lot.
>From above link, I manually insert the word joiner character by
binding a command that calls `insert-char', but it was too cumbersome.
I made following minor mode, which inserts the word joiner if it
detects the need.
--BEGINNING-OF-SCRIPT--
(defun different-command-p (command name)
"Return t iff COMMAND is a command and has different from NAME"
(and (commandp command)
(not (eq name command))
;string-match name (symbol-name command)))
command))
(defun call-next-command (keys not-this-command)
"Interactively call the command that has a binding of KEYS, but
not NOT-THIS-COMMAND"
(let ((command (catch 'found
(mapc (lambda (map)
(let ((cmd (different-command-p
(lookup-key map keys)
not-this-command)))
(when cmd
(throw 'found cmd))))
(current-minor-mode-maps))
(or (different-command-p (lookup-key (current-local-map)
keys)
not-this-command)
(different-command-p (lookup-key (current-global-map)
keys)
not-this-command)))))
(when (commandp command)
(call-interactively command))))
(defun org-insert-word-joiner-or-space ()
(interactive)
(save-match-data
(when (looking-back "\\([=/]\\)\\(.*\\)\\1\\([^[:space:]\u2060]+\\)"
(line-beginning-position) 'greedy)
;; 2nd match => emphasised phrase (e.g. =code=)
;; 3rd match => partial word appended
(save-excursion
(goto-char (match-beginning 3))
(insert-char #x2060)))
(call-next-command (this-command-keys-vector)
'org-insert-word-joiner-or-space)))
(defvar org-wordjoin-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [?\ ] 'org-insert-word-joiner-or-space)
(define-key map [(control ?j)] 'org-insert-word-joiner-or-space)
(define-key map [(control ?m)] 'org-insert-word-joiner-or-space)
(define-key map [(tab)] 'org-insert-word-joiner-or-space)
map)
"Keymap for `org-wordjoin-mode'")
(define-minor-mode org-wordjoin-mode
"Enable automatic insertion of word joiner"
nil
" WordJoin"
:keymap org-wordjoin-mode-map)
--END-OF-SCRIPT--
Q1. Is there better way to do this? (esp. I think the regular
expression in `looking-back' is not 100% compatible with
org-mode's pattern for the emphasis. But I couldn't come up with
better one.)
Q2. If I remember correctly, I read from the mailing list that partial
word emphasis will not be supported in org-mode. Is it possible
to org-mode to include this kind of minor mode? If possible, I
hope that some experts can come up with better implementation of
this and include that in the official package. Or, at least
insert "word joiner" character character in
`org-emphasis-regexp-components' please.
Thank you,
- [O] Partial word emphasis suggestion,
cinsky <=