Skip to content

Instantly share code, notes, and snippets.

@typester
Created January 26, 2009 12:23
Show Gist options
  • Save typester/52799 to your computer and use it in GitHub Desktop.
Save typester/52799 to your computer and use it in GitHub Desktop.
;;; -*- coding: utf-8; mode: emacs-lisp; -*-
;;; alc.el
;; Author: Daisuke Murase <typester@cpan.org>
;; Keywords: alc
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;; Prefix: alc-
;;; Commentary:
;; Tested on Emacs 22
;; TODO:
;; Implement more functions
;;;code:
(require 'url)
(require 'url-util)
(defun alc-strip-tags (html)
"strip alc html tags"
(with-temp-buffer
(insert html)
(beginning-of-buffer)
(replace-regexp "\\(?:<.*?>\\|\r?\n\\)" "")
(beginning-of-buffer)
(replace-regexp "\\(【\\)" "\n\\1")
(beginning-of-buffer)
(replace-regexp "\\(・.*?:\\)" "\n \\1")
(buffer-string)))
(defun alc-lookup (word)
"lookup alc web dictionary and show result to minibuffer"
(interactive
(let* ((cur (or (thing-at-point 'word) ""))
(val (read-string (if (string-match "^[0-9A-Za-z_]+$" cur)
(format "Alc Lookup (default %s): " cur)
"Alc Lookup: ")
nil nil cur)))
(list val)))
(let ((url (format "http://eow.alc.co.jp/%s/" (url-hexify-string word)))
(cb (lambda (status)
(url-mark-buffer-as-dead (current-buffer))
(if status
(message status)
(let ((raw (buffer-string)))
(with-temp-buffer
(insert (decode-coding-string raw 'utf-8))
(beginning-of-buffer)
(if (re-search-forward "<li>\\(\\(?:[\r\n]\\|.\\)+?\\)</li>" nil t)
(message (alc-strip-tags (match-string 1)))
(message "not found"))))))))
(url-retrieve url cb)))
(provide 'alc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment