emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: cinsky@gmail.com
To: emacs-orgmode@gnu.org
Cc: cinsky@gmail.com
Subject: Partial word emphasis suggestion
Date: Sun, 02 Mar 2014 10:04:57 +0900	[thread overview]
Message-ID: <m2fvn1if5y.fsf@gmail.com> (raw)


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,

             reply	other threads:[~2014-03-02  1:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-02  1:04 cinsky [this message]
2014-03-17  2:04 ` Partial word emphasis suggestion Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2fvn1if5y.fsf@gmail.com \
    --to=cinsky@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).