;; -*- coding: utf-8 -*- ;; 2012-04-06 ;; http://xahlee.org/emacs/xah_emacs_init.html (defun insert-atom-entry (&optional altLinkUrl) "Insert a Atom webfeed entry template, in the current buffer's cursor position. If ALTLINKURL is given, it is used in the link tag. Example: If ALTLINKURL is http://xahlee.org/emacs/blog.html then otherwise the alt link used is: " (interactive) (let (textToInsert domainName ) (when (equal altLinkUrl nil) (setq altLinkUrl "http://xahlee.org/Periodic_dosage_dir/pd.html") ) (setq domainName (cond ((string-match "http://xahporn\\.org/" altLinkUrl) "xahporn.org") ((string-match "http://xahlee\\.org/" altLinkUrl) "xahlee.org") (t (error "%s" "Code logic error. 2va8re2ufk")) ; only expect the above 2 ) ) (insert (format " %s %s
" (new-atom-id-tag domainName) (current-date-time-string) altLinkUrl )) ) ) (defun new-atom-id-tag (&optional domainName) "Returns a newly generated ATOM webfeed's “id” element string. Example of return value: 「tag:xahlee.org,2010-03-31:022128」 If DOMAINNAME is given, use that for the domain name. Else, use “xahlee.org”." (format "tag:%s%s" (if domainName domainName "xahlee.org") (format-time-string ",%Y-%m-%d:%H%M%S" (current-time) 1)) ) (defun xah-make-atom-entry () "Create a Atom (RSS) entry of the current blog file. Use current line or selected text as input, and update the Atom file's overall “updated” tag. Note: this command is customized for xah lee's file structures. Much of things are implicit. If the current file is〔~/web/xahlee_org/emacs/blog.html〕, then the blog will be blog.xml Other files paths for blogs are: ~/web/xahlee_org/Periodic_dosage_dir/pd.html ~/web/xahlee_org/arts/blog.html ~/web/xahlee_org/blender/blog.html ~/web/xahlee_org/comp/blog.html ~/web/xahlee_org/emacs/blog.html ~/web/xahlee_org/js/blog.html ~/web/xahlee_org/math/blog.html ~/web/xahlee_org/piano/blog.html ~/web/xahlee_org/lit/blog.html ~/web/xahlee_org/sex/blog.html ~/web/xahlee_org/sl/blog.html the Atom files names will be same as blog file name but with suffix “.xml”." (interactive) (let (bds p1 p2 inputStr currentFileDir currentFileName blogFileName blogFilePath altUrl) (setq bds (get-selection-or-unit 'line)) (setq inputStr (elt bds 0) p1 (elt bds 1) p2 (elt bds 2) ) ;; (setq p1 (line-beginning-position) ) ;; (setq p2 (line-end-position) ) ;; (setq inputStr (buffer-substring-no-properties p1 p2)) (setq currentFileName (file-name-nondirectory (buffer-file-name))) (setq currentFileDir (file-name-directory (buffer-file-name))) ; ends in slash (setq blogFileName (concat (file-name-sans-extension (file-name-nondirectory currentFileName)) ".xml")) (setq blogFilePath (concat currentFileDir blogFileName)) (setq altUrl (concat (cond ((string-match "xahporn_org/" currentFileDir) "http://xahporn.org/") ((string-match "xahlee_org/" currentFileDir) "http://xahlee.org/") (t (error "%s" "Code logic error: wqc90wmqve")) ; only expect the above 2 ) (cond ((string-match "arts/$" currentFileDir) "arts/blog.html") ((string-match "blender/$" currentFileDir) "blender/blog.html") ((string-match "comp/$" currentFileDir) "comp/blog.html") ((string-match "emacs/$" currentFileDir) "emacs/blog.html") ((string-match "js/$" currentFileDir) "js/blog.html") ((string-match "lit/$" currentFileDir) "lit/blog.html") ((string-match "math/$" currentFileDir) "math/blog.html") ((string-match "piano/$" currentFileDir) "piano/blog.html") ((string-match "sex/$" currentFileDir) "sex/blog.html") ((string-match "sl/$" currentFileDir) "sl/blog.html") ((string-match "xahporn_org/porn/$" currentFileDir) "porn/blog.html") ((string-match "Periodic_dosage_dir/$" currentFileDir) "Periodic_dosage_dir/pd.html") (t (error "%s" "Code logic error: 46fqpzzozw")) ; only expect the above ) )) (find-file blogFilePath) (goto-char 1) (search-forward "" nil t) (beginning-of-line) (insert-atom-entry altUrl) (search-backward "
" nil t) (search-forward ">" nil t) (insert "\n" inputStr) ;; update atom date (progn (goto-char 1) (search-forward "" nil t) (delete-char 25) (insert-date-time)) (search-forward ">�" nil t) ) )