tabbar mode rocks with customization!

 

 

Why doing this

I like tabbar mode, and it gives Emacs a “modern” feeling – similar to that available in most web browsers such as my
favorite Firefox.

However, I don’t like the default settings of tabbar mode. So here comes my customization:

color and separator

my current tabbar tabs looks:


And the customization code in .emacs file are:

(setq tabbar-background-color "#959A79") ;; the color of the tabbar background
(custom-set-faces
 '(tabbar-default ((t (:inherit variable-pitch :background "#959A79" :foreground "black" :weight bold))))
 '(tabbar-button ((t (:inherit tabbar-default :foreground "dark red"))))
 '(tabbar-button-highlight ((t (:inherit tabbar-default))))
 '(tabbar-highlight ((t (:underline t))))
 '(tabbar-selected ((t (:inherit tabbar-default :background "#95CA59"))))
 '(tabbar-separator ((t (:inherit tabbar-default :background "#95CA59"))))
 '(tabbar-unselected ((t (:inherit tabbar-default)))))

key bindings:

I use C-S-< and C-S-> to jump among tabs in the same group, and use C-S-n and C-S-p to switch among groups. Here is the
code in .emacs file:

(global-set-key (kbd "C-S-p") 'tabbar-backward-group)
(global-set-key (kbd "C-S-n") 'tabbar-forward-group)
(global-set-key (kbd "C-<") 'tabbar-backward)
(global-set-key (kbd "C->") 'tabbar-forward) ;; tabbar.el, put all the buffers on the tabs.

my favorite tabbar customization: to toggle between 2 different grouping schemes

  • grouping tabs by major mode (the default)
  • grouping tabs by dir the files belonging to

here is the effect:

  • grouping by dir (see how the org, tex, html, and bbl buffers under the same publishing project are grouped together)

  • grouping by major modes (see how all org buffers are grouped together)

here is the code

(defun tabbar-buffer-groups-by-dir ()
        "Put all files in the same directory into the same tab bar"
        (with-current-buffer (current-buffer)
          (let ((dir (expand-file-name default-directory)))
            (cond ;; assign group name until one clause succeeds, so the order is important
             ((eq major-mode 'dired-mode)
              (list "Dired"))
             ((memq major-mode
                    '(help-mode apropos-mode Info-mode Man-mode))
              (list "Help"))
             ((string-match-p "\*.*\*" (buffer-name))
              (list "Misc"))
             (t (list dir))))))

(defun tabbar-switch-grouping-method (&optional arg)
  "Changes grouping method of tabbar to grouping by dir.
With a prefix arg, changes to grouping by major mode."
  (interactive "P")
  (ignore-errors
    (if arg
      (setq tabbar-buffer-groups-function 'tabbar-buffer-groups) ;; the default setting
        (setq tabbar-buffer-groups-function 'tabbar-buffer-groups-by-dir))))

misc settings

(setq tabbar-cycle-scope (quote tabs))
(setq table-time-before-update 0.1)
(setq tabbar-use-images t)

Date: 2012-09-21

Author: Da Zhang

Org version 7.9.1 with Emacs version 24

Validate XHTML 1.0

LeechBlock – the killer of timekillers

Procrastination, the time-wasting and beating-around-the-bush type of behavior before any progress could be made on the real important things, is very typical among many people, including me.

I found that visiting my favorite websites before I start working is almost irresistible.

From Matt Might’s Productivity tips, tricks and hacks for academics and Boost your productivity: Cripple your technology, I learned about LeechBlock, which is perfect to block my favorite websites during hours I am supposed to work.

I can set up what to block (for example, http://www.cnn.com), when to block (e.g., 0900-1730), how long to block (e.g., 1 min in every hour), what to show when a page is blocked (for me, I used the Journal of Medical Physics website for most recent articles)

To protect the disciplines from being violated, the LeechBlock is actually designed in a quite tricky and clever way:

  • I can set up password to the Option dialog box of LeechBlock for someone else, like my wife, to help them fighting procrastination together;
  • or I can let LeechBlock to require me to type in a 64 or 32 digit long randomly generated combination of letters and numbers before accessing its Option dialog box, which is really a pain. (see the pictures below)

When the path toward surfing online becomes more difficult to approach, it becomes easier for me to resist the desire to do so.

BTW, I don’t think I need to block IE, because I feel that using IE to surf online is as painful as by-passing the control of LeechBlock :-).

Date: 2012-03-25 17:38:16 Eastern Daylight Time

Author: Da Zhang

Org version 7.8.03 with Emacs version 24

Validate XHTML 1.0

My color theme color-theme-dawn-night is updated and uploaded to the marmalade repository (updated)

I have been spending time to tweak and design my own color themes since 2007, and published previous
versions (switch-color-theme-matlab-latex.el) on this blog (http://zhangda.wordpress.com/2009/04/08/my-own-emacs-color-themes-i-use-f6-c-u-f6-to-switch-between-them/).

I think now it’s a good time to move the package to the more popular host, marmalade, so anyone interested could use the
emacs package management tool (package.el) to obtain it. If marmalade is included in your package-archives list (see the
code below for this), you should be able to see the package “color-theme-dawn-night” after firing up list-packages.

(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                          ("marmalade" . "http://marmalade-repo.org/packages/")))

You can also download the color-theme-dawn-night.el via http://marmalade-repo.org/packages/color-theme-dawn-night-1.0.el

Here is a brief description of the color theme:

color-theme-dawn-night.el contains two customized color themes:

(1) cl-night
is a dark-background theme, designed for normal programming,
org/muse mode editing and LaTeX editing. The foreground colors are designed
to be somewhat aqua, with a bright and warm feeling.

(2) cl-dawn
is designed with a bright and warm background. The color setup was inspired
by the light yellow background and visual effect of the Matlab programming
environment.

Call function switch-dawn-night to change to the dark face, and call C-u
switch-dawn-night for the bright background face.

Install the theme:
(1)Place color-theme-dawn-night.el into your load-path.

(2)In your .emacs, add:
(require ‘color-theme-dawn-night)

(3)optional keybinding
(global-set-key [f6] ‘switch-dawn-night)

 

One good thing to tweak the color theme is that you can have a full control of the appearance of Emacs. For example, I adjusted different faces of tabbar to make them appear uniformly and as if in a real tabbar system.  Another example is the color of the line numbers on the left fringe — I made them slim and in a “dark gold” color.

Here are some screen shots of my color themes.

color theme dawn night:  night

color-theme-dawn-night: night

color theme dawn night:  dawn

color-theme-dawn-night: dawn

Date: 2012-03-24

Author: Da Zhang

Validate XHTML 1.0

Using org-mode as the ultimate note taking tool (updated)

Whenever there is something important to memorize, I always want to write it down. In fact, Emacs org-mode makes the process easy, pleasant, and in an organized manner. I will use an example to explain how Emacs and org fit into my note-taking process.

I have a dedicated folder containing all my notes, and IT, as one of the most important topic, is a sub-folder. Here is the tree structure of the IT folder.

IT
|-- Acrobat
|   `-- startup_script.org
|-- Emacs
|   |-- debug-lisp.html
|   |-- debug-lisp.org
|   |-- emergency-elisp-steve-yegge.html
|   |-- emergency-lisp.html
|   |-- emergency-lisp.org
|   |-- lisp-programming.html
|   `-- lisp-programming.org
|-- Excel
|   `-- group_formatting.txt
|-- Firefox
|   `-- Firefox Recovery Key.html
|-- HPC
|   |-- Setup_GATE_tool_chain_20100902.lnk
|   |-- bashrc_setup
|   |   `-- bashrc_HPC
|   |-- efficient-way-of-working.html
|   |-- efficient-way-of-working.org
|   |-- tricks.html
|   |-- tricks.org
|   `-- xinhua-hps-bashrc
|-- Linux_commands
|   |-- cat.html
|   |-- cat.org
|   |-- count_files_in_dir.html
|   |-- count_files_in_dir.org
|   |-- find.html
|   |-- find.org
|   |-- find.txt
|   |-- linux_commands.html
|   |-- linux_commands.org
|   |-- scp.txt
|   |-- sed.html
|   |-- sed.org
|   |-- sed_commandline_editor.txt
|   `-- tar.txt
|-- VBA
|   `-- VBA_study_notes.org
|-- X11_cygwin
|   `-- startxwin_of_Xinhua.sh
|-- c++
|   |-- ACM-UNIX-Tutorial-Compiler.html
|   |-- C++Quick-Ref.html
|   |-- C++Std-Lib-Quick-Ref.html
|   |-- Makefiles-short.html
|   `-- gcc-intro.html
|-- cygwin
|   `-- how_to_write_.bashrc_correctly_for_cygwin.org
|-- g++
|   |-- g++compiling.txt
|   |-- gcc&g++.html
|   |-- gcc&g++.org
|   `-- note.txt
|-- gdb
|   |-- debug-tools.html
|   `-- debug-tools.org
|-- latex
|   |-- cygwin_latex_problem.html
|   |-- cygwin_latex_problem.org
|   |-- sumatrapdf-make-emacs_integration.html
|   `-- sumatrapdf-make-emacs_integration.org
|-- make
|   |-- note.html
|   `-- note.org
|-- python
|   |-- math.html
|   `-- math.org
|-- shell
|   |-- bashrc_and_others.htm
|   |-- bashrc_and_others_files
|   |   |-- css_2ad809fd00fb2c1d453a0d2b83bf7b57.css
|   |   |-- ga.js
|   |   |-- gumdrop.png
|   |   |-- index2.jpg
|   |   |-- js_957ff3e13d89532193faea68e21100f9.js
|   |   |-- js_c59e4e9c853d32975fd97f7345ddbabe.js
|   |   `-- show_ads.js
|   |-- notes.html
|   |-- notes.org
|   |-- programming.html
|   `-- programming.org
`-- ssh
    |-- How to set up SSH (for the beginner).pdf
    |-- no_password_access.html
    `-- no_password_access.org

As can be seen, almost every note has two forms: one org file, one html file. The reason that I am showing the IT folder here is to show how I organize my notes through a tree structure representing the hierarchy of related topics.

When I want to take a note, I always think first where does the topic fit into my hierarchal folder systems. Take the Linux command sed for example, I feel like it should be put in IT/Linux_commands/. Thus I enter a emacs function “notes”, which is defined in my .emacs file as

(defun notes ()
  "Switch to my work dir."
   (interactive)
   (find-file "<PATH TO MY NOTES>")
   )

This quickly bring me to my top level dir of all notes, in a dired buffer. Then I quickly follow the hierarchy to IT/Linux_commands/, where I open a file called “sed.org” via [C-x C-f sed.org]

When the file is open, I call another function “make-header”, which I customized from header2.el  for my own purpose. The function will generate a file header for me automatically, here is the result for the sed.org:

#+TITLE: sed
#+AUTHOR: Da Zhang
#+OPTIONS: H:2 num:t toc:nil
#+OPTIONS: ^:nil
#+OPTIONS: <:nil todo:nil *:t ^:{} @:t ::t |:t TeX:t
#how to change image size: #+attr_html: width="40%"

Basically it will do the following:

  1. set the title to be the file name of the buffer, without its parent path and extension;
  2. set up the options for org mode
  3. insert a note for myself about changing the picture size in org-to-html export, which I still did not remember

Then I just start writing down the quick note about sed.

* how to use variable in a sed: use "" instead of ''
CF http://www.unix.com/shell-programming-scripting/14085-how-can-i-use-variable-sed.html
 - example: note the $1 in the double quotes of the 2nd sed
ORG-LIST-END-MARKER

function sortcsvp() {
    cat $1 | sed '1d' | tr -d '"' | sort -n -t, -k 1 | sed "1 i  $1, , " > ./sort-by-protocol/$1;
}

In most cases I will use #+begin_src and #+end_src for enclose any code, for better appearance in the html output.

At the end, I will just press C-c C-e to export the entire buffer to html, which I will view more frequently from Firefox.

To conclude, Emacs and org-mode offered me a comfort environment for systematically taking notes, organize them, and exporting them into beautiful html pages.

————————————————————————————————————————————-

Thanks to Irreal’s comment.
Here is something more I want to add about using org to take notes:

(1) the org-html process is almost perfect if you want to include pictures (for example, taken from your smart phone) in the note. Writing a org file that links to the local picture file using the [[][]] structure is so easy and natural. With the html publication, your output note file contains not only text, but also graphics and pictures that makes the note taking more efficient and direct. I used this feature so often that I need to put the following trick into my org header:

#how to change image size: #+attr_html: width="40%"

(2) the hack of header2.el I talked about making is essentially putting the following lines in header2.el:

(defsubst header-org-mode ()
  "Insert \"#+TITLE: ...\" at the beginning of org file."
  (insert "#+TITLE: " (file-name-nondirectory (file-name-sans-extension (buffer-file-name))) "\n") ;; filename only, without dir or extension
  (insert "#+AUTHOR: " (user-full-name) "\n")
  (insert "#+OPTIONS: H:2 num:t toc:nil\n")
  (insert "#+OPTIONS: ^:nil\n")
  (insert "#+OPTIONS: <:nil todo:nil *:t ^:{} @:t ::t |:t TeX:t\n")
  (insert "#how to change image size: #+attr_html: width=\"40%\"\n"))

Date: 2012-03-24 02:23:35 Eastern Daylight Time

Author: Da Zhang

Org version 7.8.03 with Emacs version 24

Validate XHTML 1.0

SumatraPDF integration in LaTeX-Emacs-make tool chain

 

SumatraPDF integration in LaTeX-Emacs-make tool chain

steps:

1.upgrade to the most recent SumatraPDF http://code.google.com/p/sumatrapdf/downloads/list

2.make sure sumatrapdf is in the search path

3.update make file for the make integration

MAIN=maintex

EPS=img/*.eps

TEX=tomo_spectra.tex 

BIB=da.bib 

REBUILDABLES =  \
*.log   \
*.blg   \
*.bbl   \
*.aux   \
*.lof   \
*.lot   \

LATEXOPTIONS = -src-specials -interaction=nonstopmode

PDFVIEWER = sumatrapdf -reuse-instance -inverse-search "c:\emacs\bin\emacsclientw.exe +%l \"%f\""

BIBDIR = "C:/H/Bib"

BIBOPTIONS = -include-directory=$(BIBDIR)

vpath %.bib /cygdrive/c/H/Bib

viewpdf : $(MAIN).pdf
    $(PDFVIEWER) $(MAIN).pdf &

dvi : $(MAIN).dvi
    yap -1  $(MAIN).dvi

$(MAIN).pdf : $(MAIN).dvi
    pdfclosem $(MAIN).pdf ; dvipdfm $(MAIN).dvi

$(MAIN).dvi : $(MAIN).bbl $(EPS)
    latex $(LATEXOPTIONS) $(MAIN)
        if ( grep 'Rerun' $(MAIN).log > /dev/null ) ; then\
            latex $(LATEXOPTIONS) $(MAIN) ; \
        else :; fi

$(MAIN).bbl : $(TEX)
    rm -f $(MAIN).aux *.bbl; latex $(LATEXOPTIONS) $(MAIN); bibtex $(BIBOPTIONS) $(MAIN) 

clean :
    rm -f $(REBUILDABLES)

4.update .emacs for AucTeX integration

(setq TeX-view-program-list
      '(("sumatra" "sumatrapdf -reuse-instance \"%f\"")
        ("Yap" ("yap -1" (mode-io-correlate " -s %n%b") " %o"))
        ("dvips and start" "dvips %d -o && start \"\" %f")
        ("start" "pdfviewm %o")))

(setq TeX-view-program-selection
      '(((output-dvi style-pstricks)
         "dvips and start")
        (output-dvi "Yap")
        (output-pdf "sumatra")
        (output-html "start")))

if I need inverse search, pub /usepackage{pdfsync} before \begin{document}, or use pdflatex instead of latex

why using sumatrapdf? it does not lock the pdf file, so when restarting the make process, I don’t need to close the pdf file manually.

Date: 2012-02-16

Author: Da Zhang

Org version 7.8.03 with Emacs version 24

Validate XHTML 1.0

tried org2blog mode successfully

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.

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

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