Changeset 14729 for lang/gauche

Show
Ignore:
Timestamp:
06/28/08 01:23:18 (5 months ago)
Author:
kiyoka
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/gauche/oldtype/trunk/Kahua/oldtype/oldtype/oldtype-mode.el

    r13658 r14729  
    2929;; 
    3030;; ChangeLog: 
     31;;   [0.0.6] 
     32;;     1. Improved URL to [URL|TITLE] conversion feature.  ( C-c C-c key ) 
     33;;        oldtype-mode.el fetches remote title page and insert TITLE. 
     34;; 
    3135;;   [0.0.5] 
    3236;;     1. Fixed bug: [return] key breaks japanese input method UI. 
     
    599603        (newline)))) 
    600604 
     605 
     606;; 
     607;; [fetch command] 
     608;;   w3m -no-graph -halfdump -o ext_halfdump=1 -o strict_iso2022=0 -o fix_width_conv=1 URL 
     609;;       | awk '-F<' '/title_alt/ { print $2; }' | tail -1 | awk '-F"' '{ print $2; }' 
     610;; 
     611(defun oldtype-fetch-html-title (url) 
     612  (cond  
     613   ((string-match "http://" url) 
     614    (with-temp-buffer 
     615      (shell-command  
     616       (concat 
     617        (format "w3m -no-graph -halfdump -o ext_halfdump=1 -o strict_iso2022=0 -o fix_width_conv=1 \'%s\' |" url) 
     618        "awk \'-F\<\' \'/title_alt/ { print $2; }\' |" 
     619        "tail -1 |" 
     620        "awk \'-F\"\' \'{ print $2; }\'") 
     621       (current-buffer)) 
     622      (replace-string "[" "<" nil (point-min) (point-max)) 
     623      (replace-string "]" ">" nil (point-min) (point-max)) 
     624      (buffer-substring-no-properties (point-min) (point-max)))) 
     625   (t 
     626    "No Title"))) 
     627 
     628 
    601629(defun oldtype-mode-hookfunc () 
    602630 
     
    649677                (insert "##(")) 
    650678              (insert str) 
    651               (insert end) 
     679xo            (insert end) 
    652680              (goto-char pos)))) 
    653681         ((equal ?< (char-after (point))) 
     
    673701          (let* ((asin  (match-string 2)) 
    674702                 (url   (match-string 0)) 
    675                  (title (if (boundp 'w3m-version) 
    676                             (or (w3m-arrived-title url) 
    677                                 "NoTitle") 
    678                           "NoTitle"))) 
    679             (delete-region (match-beginning 1) (match-end 3)) 
    680             (goto-char (match-beginning 1)) 
     703                 (s     (match-beginning 1)) 
     704                 (e     (match-end 3)) 
     705                 (title (oldtype-fetch-html-title url))) 
     706            (delete-region s e) 
     707            (goto-char s) 
    681708            (insert (format "##(amazon %s)  %s" asin title)))) 
    682709         ;; http://www.youtube.com/watch ...  youtube-command 
     
    685712          (let* ((video (match-string 2)) 
    686713                 (url   (match-string 0)) 
    687                  (title (if (boundp 'w3m-version) 
    688                             (or (w3m-arrived-title url) 
    689                                 "NoTitle") 
    690                           "NoTitle"))) 
    691             (delete-region (match-beginning 1) (match-end 3)) 
    692             (goto-char (match-beginning 1)) 
     714                 (s     (match-beginning 1)) 
     715                 (e     (match-end 3)) 
     716                 (title (oldtype-fetch-html-title url))) 
     717            (delete-region s e) 
     718            (goto-char s) 
    693719            (insert (format "##(youtube %s)  %s" video title)))) 
    694720         ;; http://host/path/of/contents... anchor-keyword 
    695721         ((string-match      (concat "^" _url_file-pattern) str) 
    696722          (re-search-forward             _url_file-pattern (point-at-eol) t) 
    697           (if (boundp 'w3m-version) 
    698               (let* ((url   (match-string 1)) 
    699                      (title (or (w3m-arrived-title url) 
    700                                 "NoTitle"))) 
    701                 (delete-region (match-beginning 1) (match-end 1)) 
    702                 (goto-char (match-beginning 1)) 
    703                 (insert (format "[[%s|%s]]" url title))) 
    704             (message "OldType: Please install emacs-w3m."))) 
     723          (let* ((url   (match-string 1)) 
     724                 (s     (match-beginning 1)) 
     725                 (e     (match-end 1)) 
     726                 (title (oldtype-fetch-html-title url))) 
     727            (delete-region s e) 
     728            (goto-char s) 
     729            (insert (format "[[%s|%s]]" url title)))) 
    705730         (t 
    706731          (message "OldType: Please move cursor to [[URL|Name]]  or [[WikiName]] *.png  or  ##(... )  keywword.' "))))))