tried org2blog mode successfully

Posted in Emacs on March 29, 2011 by zhangda

Following the blog of Gabriel Saldana “Post to WordPress blogs with Emacs & Org-mode” at http://blog.nethazard.net/post-to-wordpress-blogs-with-emacs-org-mode/#utm\_source=feed&utm\_medium=feed&utm\_campaign=feed I tested the org2blog mode.

The set up is a little different from what was described in the above post: I put the following code in my .emacs file:

(require ‘org2blog-autoloads) (setq org2blog/wp-blog-alist ‘((“wordpress” :url “http://username.wordpress.com/xmlrpc.php” :username “username” :tags-as-categories nil)))

You have to substitute the “username” with your actual username of wordpress.

To use the org2blog, you can M-x org2blog/wp-login first, and then M-x org2blog/wp-new-entry.

updated switch-color-theme-matlab-latex.el

Posted in Emacs with tags on March 17, 2011 by zhangda

I made a few changes in switch-color-theme-matlab-latex.el, and hopefully it can be enjoyed by more people.

;; Filename: switch-color-theme-matlab-latex.el
;; Description:
;; Author: Da Zhang
;; Created: Wed Jan 16 13:06:57 2008
;; Update #: 699

;; Copyright (C) 2008 Da Zhang ECE OU, zhangda@member.fsf.org

;; This 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 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., 59 Temple Place – Suite 330, Boston,
;; MA 02111-1307, USA.

;;; Commentary:

;; switch-color-theme-matlab-latex.el contains the customized color themes
;; for matlab mode (yellow background) and normal (black background). Call
;; function da-color-theme to change to the dark face, and call C-u
;; da-color-theme for the yellow background face.

;; color-theme-da-matlab is particularly designed to simulate the warm
;; yellow-green color and visual effect of Matlab programming environment

;; color-theme-da-normal is a dark theme, designed for normal programming
;; tasks such as C/C++/Java development, org/muse mode editing and LaTeX
;; editing.

;; Install theme:
;; (1)Place switch-color-theme-matlab-latex.el into your load-path.

;; (2)In your .emacs, add:
;; (require ‘switch-color-theme-matlab-latex)

;; (3)optional settings such as keybinding and hooking
;; (add-hook ‘matlab-mode-hook ‘color-theme-da-matlab)
;; (global-set-key [f6] ‘da-color-theme)

;; notes:
;; 1. hl-line: the hightlighed current line
;; 2. mode-line-XXX: the info bar near the bottom of the frame
;; 3. hilight: in dired, the face of where your mouse is pointing at
;; 4. diredp-XXX: the color theme for dired-plus, dired-details+ …

;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(defun cl-normal ()
“Color theme by Da Zhang, created 2007-07-24.”
(interactive)
(ignore-errors (color-theme-install
‘(color-theme-da-normal
(background-color . “black”)
(background-mode . dark)
(background-toolbar-color . “#cf3ccf3ccf3c”)
(border-color . “#000000000000″)
(bottom-toolbar-shadow-color . “#79e77df779e7″)
;; (cursor-color . “#A7A7A7″)
(foreground-color . “honeydew”)
;; (mouse-color . “black”))
(default ((t (:stipple nil :background “#131313″ :foreground “honeydew3″ :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :foundry “outline” :family “Bitstream Vera Sans Mono”))))
(bbdb-company ((t (nil))))
(bbdb-field-name ((t (:bold t :weight bold))))
(bbdb-field-value ((t (nil))))
(bbdb-name ((t (:underline t))))
(blue ((t (:foreground “blue”))))
(bold ((t (:bold t :weight bold))))
(bold-italic ((t (:bold t :italic t :slant italic :weight bold))))
(border ((t (:background “#000000000000″))))
(border-glyph ((t (nil))))
(buffer-menu-buffer ((t (:bold t :weight bold))))
(buffers-tab ((t (:background “black” :foreground “LightSkyBlue”))))
(button ((t (:underline t))))
(comint-highlight-prompt ((t (:bold t :weight bold))))
(compilation-column-number ((t (:foreground “DarkSlateGray1″))))
(compilation-error ((t (:bold t :weight bold :foreground “Red”))))
(compilation-info ((t (:bold t :foreground “Green1″ :weight bold))))
(compilation-line-number ((t (:foreground “magenta2″))))
(compilation-warning ((t (:bold t :foreground “Orange” :weight bold))))
(completions-common-part ((t (:width normal :weight normal :slant normal :underline nil :overline nil :strike-through nil :box nil :inverse-video nil :foreground “gray78″ :background “black” :stipple nil :height 120))))
(completions-first-difference ((t (:bold t :weight bold))))
(cperl-array-face ((t (:bold t :foreground “SkyBlue2″ :weight bold))))
(cperl-hash-face ((t (:foreground “LightBlue2″))))
(cperl-invalid-face ((t (:foreground “red”))))
(cperl-nonoverridable-face ((t (:foreground “chartreuse3″))))
;; (cursor ((t (:background “#A7A7A7″))))
(custom-button ((t (:bold t :weight bold :box (:line-width 2 :style released-button)))))
(custom-button-face ((t (:bold t :weight bold))))
(custom-button-mouse ((t (:background “grey90″ :foreground “black” :box (:line-width 2 :style released-button)))))
(custom-button-pressed ((t (:background “lightgrey” :foreground “black” :box (:line-width 2 :style pressed-button)))))
(custom-button-pressed-unraised ((t (:underline t :foreground “violet”))))
(custom-button-unraised ((t (:underline t))))
(custom-changed ((t (:background “blue” :foreground “white”))))
(custom-changed-face ((t (:background “blue” :foreground “white”))))
(custom-comment ((t (:foreground “white”))))
(custom-comment-face ((t (:foreground “white”))))
(custom-comment-tag ((t (:foreground “white”))))
(custom-comment-tag-face ((t (:foreground “white”))))
(custom-documentation ((t (nil))))
(custom-documentation-face ((t (nil))))
(custom-face-tag ((t (:underline t))))
(custom-face-tag-face ((t (:underline t))))
(custom-group-tag ((t (:foreground “dark goldenrod yellow” :weight bold :underline t))))
(custom-group-tag-1 ((t (:foreground “red” :underline t))))
(custom-group-tag-face ((t (:foreground “dark goldenrod yellow” :weight bold :underline t))))
(custom-group-tag-face-1 ((t (:foreground “red” :underline t))))
(custom-invalid ((t (:background “red” :foreground “yellow”))))
(custom-invalid-face ((t (:background “red” :foreground “yellow”))))
(custom-link ((t (:underline t :foreground “cyan1″))))
(custom-modified ((t (:background “blue” :foreground “white”))))
(custom-modified-face ((t (:background “blue” :foreground “white”))))
(custom-rogue ((t (:background “black” :foreground “pink”))))
(custom-rogue-face ((t (:background “black” :foreground “pink”))))
(custom-saved ((t (:underline t))))
(custom-saved-face ((t (:underline t))))
(custom-set ((t (:background “white” :foreground “blue”))))
(custom-set-face ((t (:background “white” :foreground “blue”))))
(custom-state ((t (:foreground “white”))))
(custom-state-face ((t (:foreground “white”))))
(custom-themed ((t (:background “blue1″ :foreground “white”))))
(custom-variable-button ((t (:bold t :underline t :weight bold))))
(custom-variable-button-face ((t (:bold t :underline t :weight bold))))
(custom-variable-tag ((t (:foreground “burlywood” :underline t))))
(custom-variable-tag-face ((t (:foreground “burlywood” :underline t))))
(cvs-filename-face ((t (:foreground “Green1″))))
(cvs-handled-face ((t (:foreground “pink”))))
(cvs-header-face ((t (:foreground “green”))))
(cvs-marked-face ((t (:bold t :foreground “green3″ :weight bold))))
(cvs-msg-face ((t (:foreground “red”))))
(cvs-need-action-face ((t (:foreground “yellow”))))
(cvs-unknown-face ((t (:foreground “grey”))))
(diff-added-face ((t (nil))))
(diff-changed-face ((t (nil))))
(diff-file-header-face ((t (:bold t :background “grey70″ :weight bold))))
(diff-hunk-header-face ((t (:background “grey85″))))
(diff-index-face ((t (:bold t :background “grey70″ :weight bold))))
(diff-removed-face ((t (nil))))
(dired-face-boring ((t (:foreground “Gray65″))))
(dired-face-directory ((t (:bold t :foreground “SkyBlue2″ :weight bold))))
(dired-face-executable ((t (:foreground “Green”))))
(dired-face-flagged ((t (:background “LightSlateGray”))))
(dired-face-header ((t (:background “grey75″ :foreground “black”))))
(dired-face-marked ((t (:foreground “DarkRed1″))))
(dired-face-permissions ((t (:background “grey75″ :foreground “black”))))
(dired-face-setuid ((t (:foreground “Red”))))
(dired-face-socket ((t (:foreground “magenta”))))
(dired-face-symlink ((t (:foreground “cyan”))))
(diredp-dir-heading ((t (:foreground “Brick” :weight bold ))))
(diredp-dir-priv ((t (:foreground “burlywood3″ :weight bold))))
(diredp-no-priv ((t )))
(diredp-file-name ((t (:foreground “gray70″ :weight bold))))
(diredp-file-suffix ((t (:foreground “gray70″ :weight normal))))
(diredp-exec-priv ((t (:foreground “LightSkyBlue” :weight bold))))
(diredp-read-priv ((t (:foreground “green3″ :weight bold))))
(diredp-write-priv ((t (:foreground “Red2″ :weight bold))))
(diredp-link-priv ((t (:foreground “gray60″ :underline t))))
(diredp-other-priv ((t (:foreground “gray30″))))
(diredp-rare-priv ((t (:foreground “red”))))
(diredp-flag-mark-line ((t (:background “DarkOrange3″))))
(diredp-date-time ((t (:foreground “honeydew3″))))

(ecb-analyse-bucket-element-face ((t (:height 1.0))))
(ecb-analyse-bucket-node-face ((t (:bold t :weight bold :height 1.0))))
(ecb-analyse-face ((t (:background “magenta”))))
(ecb-analyse-general-face ((t (:height 1.0))))
(ecb-bucket-node-face ((t (:bold t :weight bold :height 1.0))))
(ecb-default-general-face ((t (:height 1.0))))
(ecb-default-highlight-face ((t (:background “magenta”))))
(ecb-directories-general-face ((t (:height 1.0))))
(ecb-directory-face ((t (:background “magenta”))))
(ecb-directory-not-accessible-face ((t (:foreground “gray60″ :height 1.0))))
(ecb-history-face ((t (:background “magenta”))))
(ecb-history-general-face ((t (:height 1.0))))
(ecb-method-face ((t (:background “magenta”))))
(ecb-method-non-semantic-face ((t (:foreground “brown” :height 1.0))))
(ecb-methods-general-face ((t (:height 1.0))))
(ecb-mode-line-data-face ((t (nil))))
(ecb-mode-line-prefix-face ((t (:foreground “forestgreen”))))
(ecb-mode-line-win-nr-face ((t (:bold t :weight bold))))
(ecb-source-face ((t (:background “magenta”))))
(ecb-source-in-directories-buffer-face ((t (:foreground “LightBlue1″ :height 1.0))))
(ecb-source-read-only-face ((t (:italic t :slant italic))))
(ecb-sources-general-face ((t (:height 1.0))))
(ecb-tag-header-face ((t (:background “SeaGreen1″))))
(ecb-tree-guide-line-face ((t (:foreground “gray” :height 1.0))))
(ecb-type-tag-class-face ((t (:bold t :weight bold))))
(ecb-type-tag-enum-face ((t (:bold t :weight bold))))
(ecb-type-tag-group-face ((t (:bold t :foreground “dim gray” :weight bold))))
(ecb-type-tag-interface-face ((t (:bold t :weight bold))))
(ecb-type-tag-struct-face ((t (:bold t :weight bold))))
(ecb-type-tag-typedef-face ((t (:bold t :weight bold))))
(ecb-type-tag-union-face ((t (:bold t :weight bold))))
;; (ediff-fine-diff-A ((t (:foreground “navy” :background “sky blue”))))
;; (ediff-fine-diff-B ((t (:foreground “black” :background “cyan3″))))
(ediff-fine-diff-A ((t (:foreground “navy” :background “sky blue”))))
(ediff-fine-diff-B ((t (:foreground “navy” :background “sky blue”))))
(ediff-current-diff-A ((t (:foreground “gray80″ :background “#0A246F”))))
(ediff-current-diff-B ((t (:foreground “gray80″ :background “#0A246F”))))
(ediff-even-diff-A ((t (:foreground “gray80″ :background “DarkSlateGray5″))))
(ediff-even-diff-B ((t (:foreground “gray80″ :background “DarkSlateGray5″))))
(ediff-odd-diff-A ((t (:foreground “gray80″ :background “DarkSlateGray5″))))
(ediff-odd-diff-B ((t (:foreground “gray80″ :background “DarkSlateGray5″))))
(eieio-custom-slot-tag-face ((t (:foreground “light blue”))))
(escape-glyph ((t (:foreground “cyan”))))
(excerpt ((t (nil))))
(file-name-shadow ((t (:foreground “grey70″))))
(fixed ((t (:bold t :weight bold))))
(fixed-pitch ((t (:family “courier”))))
(font-lock-builtin-face ((t (:foreground “red3″ :weight bold))))
(font-lock-comment-delimiter-face ((t (:foreground “YellowGreen” :weight ultra-bold))))
(font-lock-comment-face ((t (:foreground “YellowGreen” :weight bold))))
(font-lock-constant-face ((t (:bold t :foreground “DarkOrange2″ :weight ultra-bold))))
(font-lock-doc-face ((t (:foreground “burlywood”))))
(font-lock-doc-string-face ((t (:foreground “turquoise” :weight bold))))
(font-lock-function-name-face ((t (:foreground “white” :weight ultra-bold))))
(font-lock-keyword-face ((t (:bold t :foreground “DodgerBlue” :weight ultra-bold))))
(font-lock-negation-char-face ((t (nil))))
(font-lock-preprocessor-face ((t (:foreground “green3″ :weight bold))))
(font-lock-reference-face ((t (:foreground “red3″ :weight bold))))
(font-lock-regexp-grouping-backslash ((t (:bold t :weight bold))))
(font-lock-regexp-grouping-construct ((t (:bold t :weight bold))))
(font-lock-string-face ((t (:foreground “burlywood” :weight bold))))
(font-lock-type-face ((t (:foreground “brown2″ :weight bold))))
(font-lock-variable-name-face ((t (:foreground “magenta2″ :weight bold))))
(font-lock-warning-face ((t (:bold t :foreground “Red” :weight ultra-bold))))
(font-latex-math-face ((t (:foreground “burlywood”))))
(font-latex-sedate-face ((t (:foreground “gray60″))))
(font-latex-sectioning-5-face ((t (:weight bold :bold t :foreground “red3″))))
(font-latex-bold-face ((t (:weight bold :bold t :foreground “green3″))))
(fringe ((t (:background “grey10″ :foreground “#44AACC”))));;this is what change the boundaries on both sides of the emacs window
(green ((t (:foreground “green”))))
(gui-button-face ((t (:background “grey75″ :foreground “black”))))
(gui-element ((t (nil))))
(header-line ((t (:background “grey20″ :foreground “grey90″ :box nil))))
(help-argument-name ((t (nil))))
(highlight ((t (:background “#0A247A”))))
(hl-line ((t (:background “#112233″))));; use to be #112233
(html-helper-bold-face ((t (:bold t :weight bold))))
(html-helper-italic-face ((t (:bold t :foreground “yellow” :weight bold))))
(html-helper-underline-face ((t (:underline t))))
(hyper-apropos-documentation ((t (:foreground “LightSlateGray”))))
(hyper-apropos-heading ((t (:bold t :weight bold))))
(hyper-apropos-hyperlink ((t (:foreground “sky blue”))))
(hyper-apropos-major-heading ((t (:bold t :weight bold))))
(hyper-apropos-section-heading ((t (:bold t :weight bold))))
(hyper-apropos-warning ((t (:bold t :foreground “red” :weight bold))))
(ibuffer-deletion-face ((t (:foreground “red”))))
(ibuffer-marked-face ((t (:foreground “green”))))
(ido-first-match ((t (:foreground “green3″ :bold t :weight ultra-bold))))
(ido-indicator ((t (:background “red” :foreground “yellow” :width condensed))))
(ido-only-match ((t (:foreground “Green” :weight ultra-bold))))
(ido-subdir ((t (:foreground “red”))))
(info-node ((t (:bold t :foreground “yellow” :weight bold))))
(info-xref ((t (:bold t :weight bold :underline t))))
(isearch ((t (:background “paleturquoise” :foreground “dark red”))))
(isearch-secondary ((t (:foreground “red3″))))
(isearch-fail ((t (:background “red” :foreground “black”))))
(italic ((t ( :italic t :slant italic))))
(lazy-highlight ((t (:background “paleturquoise4″))))
(left-margin ((t (nil))))
(link ((t (:foreground “cyan1″ :underline t))))
(link-visited ((t (:underline t :foreground “violet”))))
(linum ((t (:inherit shadow :foreground “burlywood” :height 90 :weight normal))))
(list-mode-item-selected ((t (:background “gray68″ :foreground “dark green”))))
(man-bold ((t (:bold t :weight bold))))
(man-heading ((t (:bold t :weight bold))))
(man-italic ((t (:foreground “yellow” :italic t))))
(man-xref ((t (:underline t))))
(match ((t (:background “RoyalBlue3″))))
;; (menu ((t (:foreground “systemmenutext” :background “systemmenu”))))
(message-cited-text ((t (:foreground “orange”))))
(message-header-contents ((t (:foreground “white”))))
(message-headers ((t (:bold t :foreground “orange” :weight bold))))
(message-highlighted-header-contents ((t (:bold t :weight bold))))
(message-url ((t (:bold t :foreground “pink” :weight bold))))
(minibuffer-prompt ((t (:foreground “#ff3300″ :weight bold))))
(mmm-face ((t (:background “black” :foreground “green”))))
(mode-line ((t (:background “black” :foreground “burlywood”))))
(mode-line-buffer-id ((t (:background “black” :foreground “burlywood”))))
(mode-line-highlight ((t (:box (:line-width 2 :color “grey40″ :style released-button)))))
(mode-line-inactive ((t (:background “grey10″ :foreground “grey80″ :box (:line-width -1 :color “grey40″ :style nil) :weight light))))
(modeline-mousable ((t (:background “Gray80″ :foreground “firebrick”))))
(modeline-mousable-minor-mode ((t (:background “Gray80″ :foreground “green4″))))
(mouse ((t (:background “black”))))
(next-error ((t (:foreground “DarkBlue” :background “gray65″))))
(nobreak-space ((t (:foreground “cyan” :underline t))))
(org-level-1 ((((class color) (min-colors 88) (background dark)) (:foreground “LightSkyBlue2″ :weight extra-bold))))
(org-level-2 ((((class color) (min-colors 88) (background dark)) (:foreground “burlywood” :weight bold))))
(org-level-3 ((((class color) (min-colors 88) (background dark)) (:foreground “YellowGreen”))))
(org-level-4 ((((class color) (min-colors 88) (background dark)) (:foreground “green3″))))
(org-level-5 ((((class color) (min-colors 88) (background dark)) (:foreground “brown2″))))
(org-level-6 ((((class color) (min-colors 88) (background dark)) (:foreground “orange”))))
(org-level-7 ((((class color) (min-colors 88) (background dark)) (:foreground “red3″))))
(org-level-8 ((((class color) (min-colors 88) (background dark)) (:foreground “purple2″))))
(org-link ((((class color) (min-colors 88) (background dark)) (:foreground “cyan3″))))
(org-column ((t (:background “black” :foreground “gray80″ :strike-through nil :underline nil :slant normal :weight normal :height 98 :family “Courier New”))))
(org-done ((t (:foreground “ForestGreen” :strike-through t :weight normal))))
(org-todo ((t (:foreground “Red” :weight normal))))
(org-special-keyword ((t (:foreground “LightSalmon” :weight normal))))
(org-date ((t (:foreground “LightSalmon” :weight normal))))
(org-document-title ((t (:foreground “gray” :weight bold))))
(org-document-info ((t (:foreground “gray” :weight normal))))
(org-hide ((t (:foreground “grey20″ :weight normal))))
(paren-blink-off ((t (:foreground “gray80″))))
(paren-match ((t (:background “MediumBlue”))))
(paren-mismatch ((t (:background “DeepPink” :foreground “LightSkyBlue”))))
(pointer ((t (nil))))
(primary-selection ((t (:background “gray65″ :foreground “DarkBlue”))))
(preview-face ((((background dark)) (:background “#0F340A”))))
(preview-reference-face ((t (:background “black” :foreground “light blue” :weight bold :height 1.1))))
(query-replace ((t (:foreground “dark red” :background “paleturquoise”))))
(red ((t (:foreground “red”))))
(region ((t (:foreground “cyan” :background “#0A249A”))))
(right-margin ((t (nil))))
(scroll-bar ((t (:foreground “systemscrollbar”))))
(secondary-selection ((t (:background “paleturquoise” :foreground “black”))))
(semantic-highlight-edits-face ((t (:background “gray20″))))
(semantic-unmatched-syntax-face ((t (:underline “red”))))
(senator-intangible-face ((t (:foreground “gray75″))))
(senator-momentary-highlight-face ((t (:background “gray30″))))
(senator-read-only-face ((t (:background “#664444″))))
(shadow ((t (:foreground “grey70″))))
(shell-option-face ((t (:foreground “LightSkyBlue1″))))
(shell-output-2-face ((t (:foreground “SeaGreen1″))))
(shell-output-3-face ((t (:foreground “Blue”))))
(shell-output-face ((t (:bold t :weight bold))))
(shell-prompt-face ((t (:foreground “red4″))))
;; (show-paren-match ((t (:background “blue”))))
(show-paren-match-face ((t (:bold t :foreground “grey85″
:background “blue”))))
(show-paren-mismatch ((t (:background “red” :foreground “white” :bold t))))
(speedbar-button-face ((t (:foreground “green3″))))
(speedbar-directory-face ((t (:foreground “light blue”))))
(speedbar-file-face ((t (:foreground “cyan”))))
(speedbar-highlight-face ((t (:background “sea green”))))
(speedbar-selected-face ((t (:foreground “red” :underline t))))
(speedbar-separator-face ((t (:background “blue” :foreground “white” :overline “gray”))))
(speedbar-tag-face ((t (:foreground “yellow”))))
(swbuff-current-buffer-face ((t (:bold t :foreground “red” :underline t :weight bold))))
(swbuff-default-face ((t (nil))))
(swbuff-separator-face ((t (:foreground “DodgerBlue1″))))
(tabbar-button ((t (:inherit tabbar-default :foreground “dark red”))))
(tabbar-button-highlight ((t (:inherit tabbar-default :background “white” :box (:line-width 2 :color “white”)))))
(tabbar-default ((t (:inherit variable-pitch :background “gray80″ :foreground “black” :box (:line-width 3 :color “gray80″)))))
(tabbar-highlight ((t (:underline t))))
(tabbar-selected ((t (:inherit tabbar-default :foreground “blue” :weight bold))))
(tabbar-separator ((t (:inherit tabbar-default))))
(tabbar-unselected ((t (:inherit tabbar-default))))
(text-cursor ((t (:background “Red3″ :foreground “black”))))
(tool-bar ((t (:background “gray80″ :foreground “black”))))
(tooltip ((t (:family “helv” :background “systeminfowindow” :foreground “systeminfotext”))))
;; (trailing-whitespace ((t (:background “yellow”))))
(underline ((t (:underline t))))
(variable-pitch ((t (:family “helv”))))
(vertical-border ((t (nil))))
(vertical-divider ((t (nil))))
(vm-xface ((t (:background “white” :foreground “black”))))
(vmpc-pre-sig-face ((t (:foreground “forestgreen”))))
(vmpc-sig-face ((t (:foreground “steelblue”))))
(which-func ((t (:foreground “DeepSkyBlue1″))))
(widget ((t (nil))))
(widget-button ((t (:bold t :weight bold))))
(widget-button-pressed ((t (:foreground “red”))))
(widget-documentation ((t (:foreground “lime green”))))
(widget-field ((t (:background “gray30″ :foreground “gray85″))))
(widget-inactive ((t (:foreground “dim gray”))))
(widget-single-line-field ((t (:background “dim gray”))))
(x-face ((t (:background “white” :foreground “black”))))
(xrdb-option-name-face ((t (:foreground “red”))))
(yellow ((t (:foreground “yellow”))))
(zmacs-region ((t (:background “gray65″))))))))

;; default background EEF2D9, FFF2D9
(defun cl-matlab ()
“Color theme by Da Zhang, created 2007-07-23.”
(interactive)
(ignore-errors (color-theme-install
‘(color-theme-da-matlab
((background-color . “light goldenrod yellow”)
(background-mode . light)
(border-color . “black”)
;; (cursor-color . “red3″)
(foreground-color . “black”)
(mouse-color . “black”))
;; default background color used to be #F0F2D9
;; (default ((t (:stipple nil :background “azure” :foreground “black” :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :foundry “outline” :family “Bitstream Vera Sans Mono”))))
;; (default ((t (:stipple nil :background “#CBA635″ :foreground “black” :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :foundry “outline” :family “Bitstream Vera Sans Mono”))))
(default ((t (:stipple nil :background “light goldenrod yellow” :foreground “black” :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :foundry “outline” :family “Bitstream Vera Sans Mono”))))
(bold ((t (:bold t :background “grey40″ :foreground “yellow” :weight bold))))
(bold-italic ((t (:italic t :bold t :slant italic :weight bold))))
(border ((t (:background “yellow”))))
(buffer-menu-buffer ((t (:bold t :weight bold))))
(button ((t (:underline t))))
(comint-highlight-prompt ((t (:bold t :weight bold))))
(compilation-column-number ((t (:foreground “DarkBlue”))))
(compilation-error ((t (:bold t :weight bold :foreground “Pink”))))
(compilation-info ((t (:bold t :foreground “Green3″ :weight bold))))
(compilation-line-number ((t (:bold t :weight ultra-bold :foreground “saddle brown”))))
(compilation-warning ((t (:bold t :foreground “Orange” :weight bold))))
(completions-common-part ((t (:width normal :weight normal :slant normal :underline nil :overline nil :strike-through nil :box nil :inverse-video nil :foreground “black” :background “light goldenrod yellow” :stipple nil :height 120))))
(completions-first-difference ((t (:bold t :weight bold))))
;; (completions-first-difference ((t (:bold t :weight bold :foreground “red” :background “grey40″))))
;; (cursor ((t (:foreground “black” :background “red3″))))
(custom-button ((t (:background “lightgrey” :foreground “black” :box (:line-width 2 :style released-button)))))
(custom-button-mouse ((t (:background “grey90″ :foreground “black” :box (:line-width 2 :style released-button)))))
(custom-button-pressed ((t (:background “lightgrey” :foreground “black” :box (:line-width 2 :style pressed-button)))))
(custom-button-pressed-unraised ((t (:underline t :foreground “magenta4″))))
(custom-button-unraised ((t (:underline t))))
(custom-changed ((t (:background “blue1″ :foreground “white”))))
(custom-comment ((t (:background “gray85″))))
(custom-comment-tag ((t (:foreground “blue4″))))
(custom-documentation ((t (nil))))
(custom-face-tag ((t (:bold t :family “helv” :weight bold :height 1.2))))
(custom-group-tag ((t (:bold t :foreground “blue1″ :weight bold :height 1.2))))
(custom-group-tag-1 ((t (:bold t :family “helv” :foreground “red1″ :weight bold :height 1.2))))
(custom-invalid ((t (:background “red1″ :foreground “yellow1″))))
(custom-link ((t (:underline t :foreground “blue1″))))
(custom-modified ((t (:background “blue1″ :foreground “white”))))
(custom-rogue ((t (:background “black” :foreground “pink”))))
(custom-saved ((t (:underline t))))
(custom-set ((t (:background “white” :foreground “blue1″))))
(custom-state ((t (:foreground “dark green”))))
(custom-themed ((t (:background “blue1″ :foreground “white”))))
(custom-variable-button ((t (:bold t :underline t :weight bold))))
(custom-variable-tag ((t (:bold t :family “helv” :foreground “blue1″ :weight bold :height 1.2))))

(diredp-file-name ((t (:foreground “gray30″ :weight bold))))
(diredp-file-suffix ((t (:foreground “gray30″ :weight normal))))
(diredp-dir-heading ((t (:foreground “DarkGreen” :weight bold ))))
(diredp-dir-priv ((t (:foreground “DarkBlue” :weight bold))))
(diredp-no-priv ((t )))
(diredp-exec-priv ((t (:foreground “Blue3″ :weight bold))))
(diredp-read-priv ((t (:foreground “Green3″ :weight bold))))
(diredp-write-priv ((t (:foreground “Red3″ :weight bold))))
(diredp-link-priv ((t (:foreground “gray30″ :underline t))))
(diredp-other-priv ((t (:foreground “gray10″))))
(diredp-rare-priv ((t (:foreground “red”))))
(diredp-flag-mark-line ((t (:background “DarkOrange4″))))
(diredp-date-time ((t (:foreground “black”))))

(ecb-analyse-bucket-element-face ((t (:foreground “brown” :height 1.0))))
(ecb-analyse-bucket-node-face ((t (:bold t :weight bold :height 1.0))))
(ecb-analyse-face ((t (:background “cornflower blue” :foreground “yellow”))))
(ecb-analyse-general-face ((t (:height 1.0))))
(ecb-bucket-node-face ((t (:bold t :weight bold :height 1.0))))
(ecb-default-general-face ((t (:height 1.0))))
(ecb-default-highlight-face ((t (:background “cornflower blue” :foreground “yellow”))))
(ecb-directories-general-face ((t (:height 1.0))))
(ecb-directory-face ((t (:background “cornflower blue” :foreground “yellow”))))
(ecb-directory-not-accessible-face ((t (:foreground “gray60″ :height 1.0))))
(ecb-history-face ((t (:background “cornflower blue” :foreground “yellow”))))
(ecb-history-general-face ((t (:height 1.0))))
(ecb-method-face ((t (:background “cornflower blue” :foreground “yellow”))))
(ecb-method-non-semantic-face ((t (:foreground “brown” :height 1.0))))
(ecb-methods-general-face ((t (:height 1.0))))
(ecb-mode-line-data-face ((t (nil))))
(ecb-mode-line-prefix-face ((t (:foreground “forestgreen”))))
(ecb-mode-line-win-nr-face ((t (:bold t :weight bold))))
(ecb-source-face ((t (:background “cornflower blue” :foreground “yellow”))))
(ecb-source-in-directories-buffer-face ((t (:foreground “medium blue” :height 1.0))))
(ecb-source-read-only-face ((t (:italic t :slant italic))))
(ecb-sources-general-face ((t (:height 1.0))))
(ecb-tag-header-face ((t (:background “SeaGreen1″))))
(ecb-tree-guide-line-face ((t (:foreground “grey” :height 1.0))))
(ecb-type-tag-class-face ((t (:bold t :weight bold))))
(ecb-type-tag-enum-face ((t (:bold t :weight bold))))
(ecb-type-tag-group-face ((t (:bold t :foreground “dim gray” :weight bold))))
(ecb-type-tag-interface-face ((t (:bold t :weight bold))))
(ecb-type-tag-struct-face ((t (:bold t :weight bold))))
(ecb-type-tag-typedef-face ((t (:bold t :weight bold))))
(ecb-type-tag-union-face ((t (:bold t :weight bold))))
(eieio-custom-slot-tag-face ((t (:foreground “blue”))))
(escape-glyph ((t (:foreground “brown”))))
(file-name-shadow ((t (:foreground “grey50″))))
(fixed-pitch ((t (:family “courier”))))
(fl-comment-face ((t (:foreground “medium purple”))))
(fl-function-name-face ((t (:foreground “green”))))
(fl-keyword-face ((t (:foreground “LightGreen”))))
(fl-string-face ((t (:foreground “light coral”))))
(fl-type-face ((t (:foreground “cyan”))))
(flyspell-duplicate ((t (:foreground “DarkRed3″ :underline t :weight bold))))
(flyspell-incorrect ((t (:foreground “Red2″ :underline t :weight bold))))
(font-lock-builtin-face ((t (:foreground “dark blue” :weight bold))))
(font-lock-comment-delimiter-face ((t (:foreground “dark green” :weight bold))))
(font-lock-comment-face ((t (:foreground “dark green” :weight bold))))
(font-lock-constant-face ((t (:bold t :foreground “DarkBlue” :weight extra-bold))))
(font-lock-doc-face ((t (:bold t :foreground “purple4″ :weight bold))))
(font-lock-function-name-face ((t (:bold t :foreground “red4″ :weight bold))))
(font-lock-keyword-face ((t (:bold t :foreground “blue3″ :weight bold))))
(font-lock-negation-char-face ((t (nil))))
(font-lock-preprocessor-face ((t (:foreground “LightSteelBlue” :weight bold))))
(font-lock-regexp-grouping-backslash ((t (:bold t :weight bold :foreground “NavyBlue” ))))
(font-lock-regexp-grouping-construct ((t (:bold t :weight bold :foreground “NavyBlue” ))))
(font-lock-string-face ((t (:bold t :foreground “DarkRed” :weight bold))))
(font-lock-type-face ((t (:foreground “dark blue” :weight bold))))
(font-lock-variable-name-face ((t (:bold t :foreground “saddle brown” :weight bold))))
(font-lock-warning-face ((t (:bold t :foreground “Pink” :weight extra-bold))))
(font-latex-math-face ((t (:foreground “red4″))))
(font-latex-sedate-face ((t (:foreground “gray50″))))
(font-latex-sectioning-5-face ((t (:weight bold :bold t :foreground “red3″))))
(font-latex-bold-face ((t (:weight bold :bold t :foreground “dark green”))))
(fringe ((t (:background “#E0F2D9″ :foreground “#112233″))))
(header-line ((t (:background “grey90″ :foreground “grey20″ :box nil))))
(help-argument-name ((t (nil))))
(highlight ((t (:background “#0A247A” :foreground “light goldenrod yellow”))))
(hl-line ((t (:background “#B5BA99″))))
(html-helper-bold-face ((t (:bold t :weight bold))))
(html-helper-italic-face ((t (:bold t :background “black” :foreground “yellow” :weight bold))))
(html-helper-underline-face ((t (:underline t))))
(ibuffer-deletion-face ((t (:foreground “red”))))
(ibuffer-marked-face ((t (:foreground “darkblue”))))
(ido-first-match ((t (:foreground “blue2″ :bold t :weight ultra-bold))))
(ido-indicator ((t (:background “red” :foreground “yellow” :width condensed))))
(ido-only-match ((t (:foreground “darkgreen” :weight ultra-bold))))
(ido-subdir ((t (:foreground “red”))))
(info-node ((t (:bold t :foreground “green3″ :weight bold))))
(info-xref ((t (:bold t :weight bold :underline t))))
(isearch ((t (:background “magenta3″ :foreground “lightskyblue1″))))
(isearch-secondary ((t (:foreground “red3″))))
(isearch-fail ((t (:background “red” :foreground “black”))))
(italic ((t (:italic t :slant italic))))
(lazy-highlight ((t (:background “paleturquoise”))))
(link ((t (:foreground “blue1″ :underline t))))
(link-visited ((t (:underline t :foreground “magenta4″))))
(linum ((t (:inherit shadow :foreground “DarkGreen” :height 100 :weight normal))))
(match ((t (:background “yellow”))))
(man-bold ((t (:bold t :weight bold))))
(man-heading ((t (:bold t :weight bold))))
(man-italic ((t (:italic t :foreground “MediumBlue”))))
(man-xref ((t (:underline t))))
;; (menu ((t (:foreground “systemmenutext” :background “systemmenu”))))
(message-cited-text-face ((t (:foreground “red”))))
(message-header-cc-face ((t (:bold t :foreground “green4″ :weight bold))))
(message-header-name-face ((t (:foreground “DarkGreen”))))
(message-header-newsgroups-face ((t (:italic t :bold t :foreground “yellow” :slant italic :weight bold))))
(message-header-other-face ((t (:foreground “#b00000″))))
(message-header-subject-face ((t (:foreground “green3″))))
(message-header-to-face ((t (:bold t :foreground “green2″ :weight bold))))
(message-header-xheader-face ((t (:foreground “blue”))))
(message-mml-face ((t (:foreground “ForestGreen”))))
(message-separator-face ((t (:foreground “blue3″))))
(minibuffer-prompt ((t (:foreground “medium blue” :weight bold))))
(mode-line ((t (:background “#959A79″ :foreground “black” :weight bold))))
(mode-line-buffer-id ((t (:background “wheat” :foreground “black” :weight bold))))
(mode-line-highlight ((t (:box (:line-width 2 :color “grey30″ :style released-button)))))
(mode-line-inactive ((t (:background “#D5AA79″ :foreground “black” :box (:line-width -1 :color “grey50″ :style nil) :weight light))))
(modeline-mousable ((t (:background “wheat” :foreground “black”))))
(modeline-mousable-minor-mode ((t (:background “wheat” :foreground “black”))))
(mouse ((t (:background “black”))))
(next-error ((t (:background “gray80″))))
(nobreak-space ((t (:foreground “brown” :underline t))))
(org-level-1 ((((class color) (min-colors 88) (background dark)) (:foreground “brown” :weight extra-bold))))
(org-level-2 ((((class color) (min-colors 88) (background dark)) (:foreground “darkBlue” :weight bold))))
(org-level-3 ((((class color) (min-colors 88) (background dark)) (:foreground “DarkGreen3″ :weight bold))))
(org-level-4 ((((class color) (min-colors 88) (background dark)) (:foreground “Black”))))
(org-level-5 ((((class color) (min-colors 88) (background dark)) (:foreground “Blue3″))))
(org-level-6 ((((class color) (min-colors 88) (background dark)) (:foreground “Brick3″))))
(org-level-7 ((((class color) (min-colors 88) (background dark)) (:foreground “DarkRed1″))))
(org-level-8 ((((class color) (min-colors 88) (background dark)) (:foreground “DarkBlue3″))))
(org-link ((((class color) (min-colors 88) (background dark)) (:foreground “blue3″ :weight bold :underline t))))
(org-special-keyword ((t (:foreground “LightSalmon3″ :weight normal))))
(org-date ((t (:foreground “LightSalmon3″ :weight normal))))
(org-sexp-date ((t (:foreground “blue3″ :weight normal))))
(org-hide ((t (:foreground “light goldenrod yellow3″ :weight normal))))
(org-document-title ((t (:foreground “gray20″ :weight bold))))
(org-document-info ((t (:foreground “gray20″ :weight bold))))
(paren-blink-off ((t (:foreground “gray50″))))
(paren-match ((t (:background “MediumBlue”))))
(paren-mismatch ((t (:background “DeepPink” :foreground “LightSkyBlue”))))
(pointer ((t (nil))))
(primary-selection ((t (:background “DarkBlue” :foreground “Gray80″))))
(query-replace ((t (:foreground “lightskyblue1″ :background “magenta3″))))
(region ((t (:foreground “black” :background “gray80″))))
(scroll-bar ((t (:foreground “systemscrollbar”))))
(secondary-selection ((t (:background “darkslateblue” :foreground “black”))))
(semantic-decoration-on-private-members-face ((t (:background “#8fffff”))))
(semantic-decoration-on-protected-members-face ((t (:background “#fffff8″))))
(semantic-highlight-edits-face ((t (:background “gray90″))))
(semantic-tag-boundary-face ((t (:overline “blue”))))
(semantic-tag-highlight-face ((t (:background “#FFFFAA”))))
(semantic-tag-highlight-start-face ((t (:background “#FFFFAA”))))
(semantic-unmatched-syntax-face ((t (:underline “red”))))
(senator-intangible-face ((t (:foreground “gray25″))))
(senator-momentary-highlight-face ((t (:background “gray70″))))
(senator-read-only-face ((t (:background “#CCBBBB”))))
(shadow ((t (:foreground “grey50″))))
(show-paren-match ((t (:background “DodgerBlue”))))
(show-paren-mismatch ((t (:background “red” :foreground “white”))))
(speedbar-button-face ((t (:foreground “green4″))))
(speedbar-directory-face ((t (:foreground “blue4″))))
(speedbar-file-face ((t (:foreground “cyan4″))))
(speedbar-highlight-face ((t (:background “green”))))
(speedbar-selected-face ((t (:foreground “red” :underline t))))
(speedbar-separator-face ((t (:background “blue” :foreground “white” :overline “gray”))))
(speedbar-tag-face ((t (:foreground “brown”))))
(swbuff-current-buffer-face ((t (:bold t :foreground “red” :underline t :weight bold))))
(swbuff-default-face ((t (nil))))
(swbuff-separator-face ((t (:foreground “blue”))))
(tabbar-button-face ((t (:background “gray72″ :family “helv” :foreground “dark red” :box (:line-width 2 :color “white” :style released-button) :height 0.8))))
(tabbar-default-face ((t (:family “helv” :background “gray72″ :foreground “gray60″ :height 0.8))))
(tabbar-selected-face ((t (:background “gray72″ :family “helv” :foreground “blue” :box (:line-width 2 :color “white” :style released-button) :height 0.8))))
(tabbar-separator-face ((t (:foreground “gray60″ :background “gray72″ :family “helv” :height 0.16000000000000003))))
(tabbar-unselected-face ((t (:foreground “gray60″ :background “gray72″ :family “helv” :box (:line-width 2 :color “white” :style pressed-button) :height 0.8))))
(tool-bar ((t (:background “systembuttonface” :foreground “systembuttontext” :box (:line-width 1 :style released-button)))))
(tooltip ((t (:family “helv” :background “systeminfowindow” :foreground “systeminfotext”))))
;; (trailing-whitespace ((t (:background “yellow”))))
(underline ((t (:underline t))))
(variable-pitch ((t (:family “helv”))))
(vertical-border ((t (nil))))
(which-func ((t (:foreground “DeepSkyBlue4″))))
(widget-button ((t (:bold t :weight bold))))
(widget-button-pressed ((t (:foreground “red1″))))
(widget-documentation ((t (:foreground “dark green”))))
(widget-field ((t (:background “gray85″))))
(widget-inactive ((t (:foreground “grey50″))))
(widget-single-line-field ((t (:background “gray85″))))
(xref-keyword-face ((t (:foreground “blue”))))
(xref-list-default-face ((t (nil))))
(xref-list-pilot-face ((t (:foreground “navy”))))
(xref-list-symbol-face ((t (:foreground “navy”))))))))

(defun cl-dark ()
“dark color theme by Da Zhang, created on 20090319.”
(interactive)
(ignore-errors (color-theme-install
‘(color-theme-da-dark
((foreground-color . “#a9eadf”)
(background-color . “101010″)
(background-mode . dark)
(background-toolbar-color . “#cf3ccf3ccf3c”)
(border-color . “#000000000000″)
(bottom-toolbar-shadow-color . “#79e77df779e7″)
;; (cursor-color . “Red3″)
(foreground-color . “honeydew”)
(mouse-color . “black”))
(bold ((t (:bold t))))
(bold-italic ((t (:italic t :bold t))))
(border ((t (:background “#000000000000″))))
(border-glyph ((t (nil))))
(default ((t (nil))))
(font-lock-builtin-face ((t (:italic t :foreground “#a96da0″))))
(font-lock-comment-face ((t (:italic t :foreground “#bbbbbb”))))
(font-lock-comment-delimiter-face ((t (:foreground “#666666″))))
(font-lock-constant-face ((t (:bold t :foreground “#197b6e”))))
(font-lock-doc-string-face ((t (:foreground “#3041c4″))))
(font-lock-doc-face ((t (:foreground “gray”))))
(font-lock-reference-face ((t (:foreground “white”))))
(font-lock-function-name-face ((t (:foreground “#356da0″))))
(font-lock-keyword-face ((t (:bold t :foreground “#bcf0f1″))))
(font-lock-preprocessor-face ((t (:foreground “#e3ea94″))))
(font-lock-string-face ((t (:foreground “#ffffff”))))
(font-lock-type-face ((t (:bold t :foreground “#364498″))))
(font-lock-variable-name-face ((t (:foreground “#7685de”))))
(font-lock-warning-face ((t (:bold t :italic nil :underline nil
:foreground “yellow”))))
(fringe ((t (:background “grey10″ :foreground “#112233″))))
(italic ((t ( :italic t :slant italic))))
(hl-line ((t (:background “#112233″))))
(minibuffer-prompt ((t (:foreground “red” :weight bold))))
(mode-line ((t (:foreground “#ffffff” :background “#333333″))))
(region ((t (:foreground nil :background “#555555″))))
(show-paren-match-face ((t (:bold t :foreground “#ffffff”
:background “#050505″))))))))

(defun da-color-theme (&optional arg)
“Changes color theme to my custom black background theme.
With a prefix arg, changes to my custom white background theme.”
(interactive “P”)
(ignore-errors
(if arg
(cl-matlab)
(cl-normal))))
(provide ‘switch-color-theme-matlab-latex)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; switch-color-theme-matlab-latex.el ends here

automatic formatting bib entry and generating proper file name for pdf file

Posted in Emacs on February 18, 2011 by zhangda

This is the subroutine I use frequently to reformat bib entries downloaded from journal websites.
It can achieve the following things:

1. rename the bib entry name as FirstAuthorLastName-Year-Title
2. it will remove the lengthy abstract and note items
3. it will generate a filename for saving pdf copy in the format of FirstAuthorLastName_Year_Title_Journal.pdf
4. it will move the url item to the end and comment it

Here is the code:

;; Filename: fbib.el
;; Author: Da Zhang
;; Usage:
;; Compile:
;; System:
;; Bugs:
;; Created: Thu Apr 29 23:38:36 2010
;; Last-Updated: Fri Oct 15 14:22:05 2010 (-14400 -0400)
;; Update #: 40
;; Description:
;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(defun fbib ()
“Format the bib entry copied from websites, and generate the file name for saving the pdf files systematically.”
(interactive)
(goto-char (point-max))
(re-search-backward “@” nil t)
(beginning-of-line)
(setq beg-pos (point))

;; remove the original bib entry name
(re-search-forward “\{” nil t)
(re-search-forward “,”)
(backward-char)
(let ((beg (point)))
(re-search-backward “\{” nil t)
(forward-char)
(delete-region beg (point)))

;; search for author name and copy it to bib entry name
(let ((tmp (point)))
(re-search-forward “author” nil t)
(re-search-forward “\{” nil t)
(let ((start (point)))
(re-search-forward “\}” nil t)
(let ((end (point)))
(if (re-search-in-region “,” start end)
(backward-word 1)
(if (re-search-in-region “and” start end)
(backward-word 2)
(re-search-forward “\}” nil t)
(backward-word 1)))))
;; (re-search-forward “and” nil t)
;; (backward-word 2)
(let ((beg (point)))
(forward-word)
(copy-region-as-kill beg (point)))
(goto-char tmp)
(yank)
(insert “-”))
;; search for year and copy it to bib entry name
(let ((tmp (point)))
(re-search-forward “year” nil t)
(re-search-forward “\{” nil t)
(let ((beg (point)))
(forward-word)
(copy-region-as-kill beg (point)))
(goto-char tmp)
(yank)
(insert “-”))

;; search for article title and copy it to bib entry name
(let ((tmp (point)))
(re-search-forward “title” nil t)
(re-search-forward “\{” nil t)
(let ((beg (point)))
(re-search-forward “\}” nil t)
(backward-char)
(copy-region-as-kill beg (point)))
(goto-char tmp)
(yank)
(let ((bib-name-end (point)))
(replace-in-region ” ” “-” tmp bib-name-end)
(replace-in-region “:” “-” tmp bib-name-end)
))

;; optional: search keywords, and kill it
(goto-char beg-pos)
(if (re-search-forward “keywords” nil t)
(progn
(beginning-of-line)
(let ((beg (point)))
(re-search-forward “\},”)
(forward-char)
(kill-region beg (point)))))

;; optional: search url, and move it to the back of the entry
(goto-char beg-pos)
(if (re-search-forward “url” nil t)
(progn
(beginning-of-line)
(kill-line)
(re-search-forward “^\}” nil t)
(forward-char)
(yank)
(re-search-backward “url” nil t)
(beginning-of-line)
(let ((beg (point)))
(end-of-line)
(comment-region beg (point)))))

;; form the pdf file name and add it to the end of the buffer
(goto-char (point-max))
(let ((tmp (point)))
(goto-char beg-pos)
(re-search-forward “author” nil t)
(re-search-forward “\{” nil t)
(let ((start (point)))
(re-search-forward “\}” nil t)
(let ((end (point)))
(if (re-search-in-region “,” start end)
(backward-word 1)
(if (re-search-in-region “and” start end)
(backward-word 2)
(re-search-forward “\}” nil t)
(backward-word 1)))))
;; (re-search-forward “and” nil t)
;; (backward-word 2)
(let ((beg (point)))
(forward-word)
(copy-region-as-kill beg (point)))
(goto-char tmp)
(yank)
(insert “_”))
(let ((tmp (point)))
(re-search-backward “year” nil t)
(re-search-forward “\{” nil t)
(let ((beg (point)))
(forward-word)
(copy-region-as-kill beg (point)))
(goto-char tmp)
(yank)
(insert “_”))
(let ((tmp (point)))
(re-search-backward “title” nil t)
(re-search-forward “\{” nil t)
(let ((beg (point)))
(re-search-forward “\}” nil t)
(backward-char)
(copy-region-as-kill beg (point)))
(goto-char tmp)
(yank)
(insert “_”))
(let ((tmp (point)))
(re-search-backward “journal” nil t)
(re-search-forward “\{” nil t)
(let ((beg (point)))
(re-search-forward “\}” nil t)
(backward-char)
(copy-region-as-kill beg (point)))
(goto-char tmp)
(yank)
(insert “.pdf”))
(beginning-of-line)
(let ((pdf-name-beg (point)))
(end-of-line)
(replace-in-region “:” “_” pdf-name-beg (point)))

;; optional: search abstract, and delete it
(goto-char beg-pos)
(if (re-search-forward “abstract” nil t)
(progn
(beginning-of-line)
(let ((beg (point)))
(re-search-forward “\}” nil t)
(end-of-line)
(kill-region beg (point)))
(kill-line)))
)

(defun re-search-in-region (pat start end)
“regexp search forward in region specified by start and end.”
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(re-search-forward pat nil t)))

(defun replace-in-region (from-string to-string start end)
“Replace from-string with to-string in region specified by start and end.”
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(while (search-forward from-string nil t) (replace-match to-string nil t))
)
)

(provide ‘fbib)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; fbib.el ends here

Let Emacs be your file processing engine, and use shell to drive it for batch processing!

Posted in Emacs with tags , , , on March 24, 2010 by zhangda

Emacs has so many wonderful text processing functions that are not available elsewhere, such as align-regexp. Therefore, it will be very attractive to write an elisp script, and use shell to call Emacs to apply the script to many files.

I have some examples for this implementation:

In ~/my_elisp.el

;; my_elisp.el starts here

;; define the function for text processing
(defun format-rpt ()
“A function to format the OCR-processed reports for further excel import.”
(interactive)
;; align the table of data–> aligned and make the numbers comma separated
(goto-char (point-min))
(re-search-forward “land-mark-regexp-pattern” nil t) ;; find the land mark in the file to start the alignment
(beginning-of-line)
(let ((beg (point))) (align-regexp beg (point-max) “\\(\\s-*\\) ” 1 1 nil)) ;; align the first time
(while (re-search-forward ” \\{2,\\}\\b” nil t) ;; add comma for excel importing “comma separated file”
(insert “,”))
(goto-char (point-min))
(re-search-forward “land-mark-regexp-pattern” nil t) ;; find the land mark in the file to start the alignment
(beginning-of-line)
(let ((beg (point))) (align-regexp beg (point-max) “\\(\\s-*\\),” 1 4 nil)) ;; align the second time
(write-file “./save_to.txt” nil) ;; save file
)

(format-rpt) ;; call the function for text processing

;; my_elisp.el ends here

Then in bash (I used cygwin), use find to drive the Emacs:

find . -name “ocr.txt” -printf ‘%h\n’| while read dir; do (cd “$dir”; emacs –no-site-file -nw –batch ocr.txt -l ~/my_lisp) done

This special find calling pattern can deal with the spaces in path in Windows OS, and make it easy for cygwin.

mintty parameters

Posted in Emacs on March 16, 2010 by zhangda

When starting Mintty, it’s better to include the following parameters:
-e /bin/bash –login

Otherwise Mintty will use the path of windows: system PATH first, user PATH second, then cygwin path ==> this will cause Windows versions of cygwin commands such as FIND to be executed.

Other tip: /cygwin/etc/profile and ~/.bashrc are the common two files controlling the behavior of bash shells.

hack on match-paren

Posted in Emacs on February 5, 2010 by zhangda

I used to use a short code "match-paren" (http://grok2.tripod.com/) when I program, especially in Lisp where parentheses are everywhere. I like this piece of code, for its simplicity and usefulness: if you bind this code to something like M-[, and when you press M-[ on a "(", the cursor goes to the matching ")" automatically. This also works when mark is activated, so you can highlight the region between two matching "(" and ")" very easily. The original code is as follows:

(defun match-paren (arg)
"Go to the matching paren if on a paren."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))))

Then sometimes I found that the code does not always work intuitively, especially when I want to highlight a region with the matching "(" and ")", so I did the following hack:
(1) when you keep hitting the key-binding, e.g., M-[, the cursor jump back and forth between its original locations, not like the original code
(2) when the mark is active, the cursor jump to the matching parenthesis and move forward one step after reaching ")" or backward one step after reaching "(", so the highlighted region contains everything between (and including) the matching "(" and ")". I found this especially useful when you want to cut a list out when programming in Lisp.

Here is my hack.

(defun da-match-paren (arg)
"Go to the matching paren if on a paren."
(interactive "p")
(cond ((and mark-active (looking-at "\\s\(")) (forward-list 1))
((and mark-active (looking-back "\\s\)")) (backward-list 1))
((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
))
(global-set-key (kbd "M-[") ‘da-match-paren)

another way to track literature

Posted in Research on February 4, 2010 by zhangda

I found using NIH or NSF grant number, such as NIH RO1-EB002123, is another good way to track a series of papers from a particular research group. Actually, the corresponding authors usually pay attention to which grants a paper should mention at the Acknowledgment part, so the papers having the same grant number are often automatically and carefully classified according to the big project they are related to. I think this is worth mentioning in my web note.

open a windows explorer at the path of the current buffer

Posted in Emacs with tags on February 3, 2010 by zhangda

I use emacs in Windows. As I edit some text based files in Emacs, sometimes I need to open a window at the path of the current buffer to visit other files. It would be nice if I can just press a key in Emacs, and have this window open. Here is my simple solution for this task in Emacs with Windows OS.

(defun open-buffer-path ()
“Run explorer on the directory of the current buffer.”
(interactive)
(shell-command (concat “explorer ” (replace-regexp-in-string “/” “\\\\” (file-name-directory (buffer-file-name)) t t))))

I bound this function to a key-binding:
(global-set-key [M-f9] ‘open-buffer-path)

Notes: the key points in the line
(shell-command (concat “explorer ” (replace-regexp-in-string “/” “\\\\” (file-name-directory (buffer-file-name)) t t)))
(1) shell-command call a command specified by a string from shell
(2) replace-regexp-in-string “/” “\\\\” replace the Unix-style path (using /) to Windows-style paht (using \), the optional arguments “t t” let replace-regexp-in-string replace literally.

how to configure NIST TNT into cygwin gcc environment

Posted in Medical Imaging, Research on November 27, 2009 by zhangda

NIST TNT and JAMA are very useful libraries designed for complex matrix based computation. The libraries are purely headers containing template based classes and subroutines. To configure the TNT into a cygwin/gcc programming environment, the following can be done:

1. download TNT and JAMA from nist.gov (http://math.nist.gov/tnt/download.html)

2. extract the header files into /usr/local/include/tnt

3. test a cpp file:

#include <tnt/tnt.h>
#include <iostream>
using namespace TNT;
using namespace std;
int main(void)
{
int M = 3;
int N = 3;
Array2D< double > A(M,N, 0.0); /* create MxN array; all zeros */

for (int i=0; i < M; i++)
for (int j=0; j < N; j++)
A[i][j] = i*10+j; /* initalize array values */

Array2D< double > B = A.copy(); /* create a new copy */

Array2D< double > C(B); /* create a new view of B */
/* Both arrays (B & C) share data */
for (int i=0; i<M; i++)
for (int j=0; j<N; j++)
cout<<"A["<<i<<"]["<<j<<"] = "<<A[i][j]<<endl;
return 0;
}

4. write a makefile

CPP = g++
OFLAG = -Wall -o
LFLAG = -l
IFLAG = -I
LIBFLAG = -L
LIBDIR = /usr/local/lib/
INCLUDEDIR = /usr/local/include/TNT/
DEBUGF = -g -D DEBUG
DEBUG = no

.SUFFIXES: .exe .cpp
.cpp.exe:
$(CPP) $(OFLAG) $@ $<
$@

try.exe: try.cpp
$(CPP) $(IFLAG) $(INCLUDEDIR) $(OFLAG) try.exe try.cpp

5. build, and run the try.exe. The result shows:

A[0][0] = 0
A[0][1] = 1
A[0][2] = 2
A[1][0] = 10
A[1][1] = 11
A[1][2] = 12
A[2][0] = 20
A[2][1] = 21
A[2][2] = 22

how to set up fftw for cygwin in Win XP

Posted in Medical Imaging, Research on November 27, 2009 by zhangda

FFTW is essential for image processing, reconstruction, and other imaging related projects.
How to integrate FFTW into cygwin-Emacs-gcc programming chain:
1. instruction to follow: the INSTALL file in the package

2. 3 steps to build: ./configure, make, make install

3. the files will be placed into
/usr/local/include
/usr/local/bin
/usr/local/lib

4. test a cpp file:

#include <fftw/fftw3.h>
#include <iostream>
using namespace std;
int main()
{
cout << "fftw3.h is included" << endl;
fftw_complex *in, *out;
fftw_plan p;
int N = 64;//size of the fft
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
p = fftw_plan_dft_1d(N, in , out, FFTW_FORWARD, FFTW_ESTIMATE);
//now start initialize in
for(int i=0; i<N; i++)
{
in[i][0] = 1;
in[i][1] = 0;
}

fftw_execute(p);//actually run the fftw routine

for(int i=0; i<N; i++)
{
cout << "out[" << i << "] = " << out[i][0] << "+" << out[i][1] << "j" << endl;
}
fftw_destroy_plan(p);//
fftw_free(in);
fftw_free(out);
}

5. write the makefile correctly:

CPP = g++
OFLAG = -Wall -o
LFLAG = -l
IFLAG = -I
LIBFLAG = -L
LIBDIR = /usr/local/lib/
INCLUDEDIR = /usr/local/include/
DEBUGF = -g -D DEBUG
DEBUG = no

.SUFFIXES: .exe .cpp
.cpp.exe:
$(CPP) $(OFLAG) $@ $<
$@

main.exe: main.cpp
$(CPP) $(IFLAG) $(INCLUDEDIR) $(OFLAG) main.exe main.cpp $(LIBDIR)libfftw3.a

6. build

7. test the program main.exe

Follow

Get every new post delivered to your Inbox.