Skip to content

Instantly share code, notes, and snippets.

@ryseto
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryseto/d6f477e7196f51b6f1fe to your computer and use it in GitHub Desktop.
Save ryseto/d6f477e7196f51b6f1fe to your computer and use it in GitHub Desktop.
(defun MyTool-speech-word()
"Speak words."
(interactive)
(let* ((str (url-hexify-string (string-word-or-region))))
(process-kill-without-query
(start-process-shell-command "speech" nil
"/usr/bin/say -r 150" (concat "\"" str "\"" )))))
(defun string-word-or-region ()
"If a region is selected, the text string of the region is returned.
Otherwise, the text string of the word is returnd."
(let ((editable (not buffer-read-only))
(pt (save-excursion (mouse-set-point last-nonmenu-event)))
beg end)
(if (and mark-active
(<= (region-beginning) pt) (<= pt (region-end)) )
(setq beg (region-beginning)
end (region-end))
(save-excursion
(goto-char pt)
(backward-char 1)
(setq end (progn (forward-word) (point)))
(setq beg (progn (backward-word) (point)))))
(buffer-substring-no-properties beg end)))
(define-key global-map (kbd "C-c s") 'MyTool-speech-word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment