You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use case:
I use MS Word, Powerpoint a lot and want to use emacs-everywhere to help edit the text in Emacs. This works fine but if use, say bold, italics in org-mode and call emacs-everywhere-finish, the resulting text pasted into the application doesn't have the formatting. May not be for everyone but here's how I made it work (and can send a patch if interested).
Define a function that converts the org buffer text into a format that preserves the formatting (In macos, I use textutil) and send it directly to clipboard - Add this function to emacs-everywhere-final-hooks
Update emacs-everywhere-finish to not copy the buffer based on the value returned by another function (this other function is a user-option)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; emacs-everywhere.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom emacs-everywhere-dont-copy-buffer-function #'always-false
"Function that returns non-nil if `emacs-everywhere-finish' should
not copy buffer text.
This is useful if you want to populate the
clipboard through an external command.
The options are
1. Never (default), i.e., always copy the buffer text
2. Any user-defined function. This function should take no arguments and
return non-nil if buffer text should not be copied."
:type '(radio
(function-item :tag "never" always-false)
(function-item :tag "User-defined function")))
(defun always-false()
nil)
(defun emacs-everywhere-finish (&optional abort)
...
(unless abort
(run-hooks 'emacs-everywhere-final-hooks)
(unless (funcall emacs-everywhere-dont-copy-buffer-function)
(gui-select-text (buffer-string))
....)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; init.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'emacs-everywhere-final-hooks #'my/formatted-copy)
(setq emacs-everywhere-dont-copy-buffer-function 'my/emacs-everywhere-dont-copy)
(defun my/emacs-everywhere-dont-copy(&optional buffer-name)
(string-match-p ".*-Microsoft Word$" (or buffer-name (buffer-name))))
(defun my/formatted-copy()
(when (and (eq major-mode 'org-mode)
(not (emacs-everywhere-markdown-p))
(executable-find "textutil"))
(let ((orig-buffer-name (buffer-name))
(org-export-show-temporary-export-buffer))
(org-export-to-buffer 'html (current-buffer) nil nil t t)
(shell-command-on-region (point-min) (point-max)
(concat "textutil -stdin -format html -stdout"
(if (my/emacs-everywhere-dont-copy orig-buffer-name)
" -convert rtf | pbcopy"
" -convert txt"))
(current-buffer) t))))
The text was updated successfully, but these errors were encountered:
This is cool too see, but I don't think should necessarily be included with the package. Perhaps there's a need for a "community wiki of snippets"-type thing.
Use case:
I use MS Word, Powerpoint a lot and want to use
emacs-everywhere
to help edit the text in Emacs. This works fine but if use, say bold, italics in org-mode and callemacs-everywhere-finish
, the resulting text pasted into the application doesn't have the formatting. May not be for everyone but here's how I made it work (and can send a patch if interested).textutil
) and send it directly to clipboard - Add this function toemacs-everywhere-final-hooks
emacs-everywhere-finish
to not copy the buffer based on the value returned by another function (this other function is a user-option)The text was updated successfully, but these errors were encountered: