Skip to content

Instantly share code, notes, and snippets.

@miyamuko
Created June 3, 2010 04:15
Show Gist options
  • Save miyamuko/423444 to your computer and use it in GitHub Desktop.
Save miyamuko/423444 to your computer and use it in GitHub Desktop.
;; カーソル化の文書を分かち書きして単語を取りだす。
;; あとで tiny-segmenter に取り込む。
(require "tiny-segmenter")
(defun segment-before (&optional (point (point)))
(segment-at point :before t))
(defun segment-after (&optional (point (point)))
(segment-at point :before nil))
(defun segment-at (point &key before)
(save-excursion
(goto-char point)
(let* ((line-start-point (progn (goto-bol) (point)))
(line (buffer-substring line-start-point
(progn (goto-eol) (point)))))
(let ((segment-w/-points (let ((pt line-start-point))
(mapcar #'(lambda (seg)
(let ((begin pt))
(incf pt (length seg))
(list seg begin pt)))
(tiny-segmenter:segment line)))))
(values-list
(find-if #'(lambda (seg/beg/end)
(multiple-value-bind (_ beg end)
(values-list seg/beg/end)
(if before
(and (< beg point) (<= point end))
(and (<= beg point) (< point end)))))
segment-w/-points))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment