zwz

I am an emacs fan. I use emacs on linux (both X window and tty), and windows as well. By using emacs, I am now os-insensitive, and working happily, mouseless. ;)


Welcome to the wiki. – DrewAdams

I create my color-theme by modifying the “tty-dark” in the color-theme library, so that it almost presents the same view on either a console or a window. Here the problem is that only 8 colors are available to emacs on a tty.

ps. It is another story. I tried the TERM xterm-256colors (and also some other terms): by M-x list-color-display in emacs, I got a list of 256 color names, but still only 8 colors were shown. I googled, but found no answer…

So I have to pick the color carefully for a consistent view. Now it is satisfying to me when I am programming in C/C++ and elisp. Here it is.

(defun color-theme-zwz ()
  "Color theme derived from tty-dark."
  (interactive)
  (color-theme-install
   '(color-theme-zwz
     ((background-color . "black")
      (background-mode . dark)
      (border-color . "blue")
      (cursor-color . "red")
      (cursor-type . box)
      (foreground-color . "gray80");"bisque")
      (mouse-color . "black"))
     ((ispell-highlight-face . highlight)
      (list-matching-lines-face . bold)
      (tinyreplace-:face . highlight)
      (view-highlight-face . highlight))
     (default ((t (nil))))
     (italic ((t (:italic t :slant italic :foreground "BlanchedAlmond"))))
     (bold ((t (:weight bold))))
     (bold-italic ((t (:underline t :weight bold :slant italic))))
     (underline ((t (:underline t :foreground "green"))))
     (strike-through ((t (:strike-through t :foreground "blue"))))
     (box ((t (:box t :background "blue"))))
     (highlight ((t (:background "blue" :foreground "yellow"))))
     (calendar-today-face ((t (:underline t))))
     (diary-face ((t (:foreground "red"))))
     (fixed-pitch ((t (:family "courier"))))
     (font-lock-builtin-face ((t (:foreground "gold"))))
     (font-lock-comment-face ((t (:foreground "cyan3" :italic t :slant italic))))
     (font-lock-comment-delimiter-face ((t (:foreground "cyan3" :italic t :slant italic))))
     (font-lock-doc-string-face ((t (:foreground "LightSalmon"))))
     (font-lock-constant-face ((t (:foreground "gold"))))
     (font-lock-function-name-face ((t (:bold t :foreground "white"))))
     (font-lock-keyword-face ((t (:foreground "brown2"))))
     (font-lock-string-face ((t (:foreground "LawnGreen"))))
     (font-lock-type-face ((t (:italic t :foreground "Orchid" :slant italic))))
     (font-lock-preprocessor-face ((t (:foreground "cyan4"))))
     (font-lock-reference-face ((t (:foreground "MediumPurple"))))
     (font-lock-variable-name-face ((t (:foreground "orange" :bold t))))
     (font-lock-warning-face ((t (:bold t :foreground "Red" :bold t))))
     (flymake-errline ((t (:underline "OrangeRed"))))
     (flymake-warnline ((t (:underline "yellow"))))
     (w3m-link-numbering ((t (:background "blue" :foreground "white" :bold t))))
     (fringe ((t (:background "DarkSlateBlue"))))
     (holiday-face ((t (:background "cyan"))))
     (info-menu-5 ((t (:underline t))))
     (info-node ((t (:italic t :bold t))))
     (info-xref ((t (:bold t))))
     (message-cited-text-face ((t (:foreground "red"))))
     (message-header-cc-face ((t (:bold t :foreground "green"))))
     (message-header-name-face ((t (:foreground "green"))))
     (message-header-newsgroups-face ((t (:italic t :weight medium :foreground "yellow"))))
     (message-header-other-face ((t (:foreground "#b00000"))))
     (message-header-subject-face ((t (:foreground "green"))))
     (message-header-to-face ((t (:weight medium :foreground "green"))))
     (message-header-xheader-face ((t (:foreground "blue"))))
     (message-mml-face ((t (:foreground "green"))))
     (message-separator-face ((t (:foreground "blue"))))
     (help-argument-name ((t (:italic t :slant italic))))
     (ido-first-match-face ((t (:bold t :weight medium))))
     (ido-indicator-face ((t (:background "blue" :foreground "yellow" :width condensed))))
     (ido-only-match-face ((t (:foreground "ForestGreen"))))
     (ido-subdir-face ((t (:foreground "green"))))
     (tooltip ((t (:background "lightyellow" :foreground "black"))))
     (modeline ((t (:background "azure" :foreground "blue"))))
     (modeline-buffer-id ((t (:background "white" :foreground "red"))))
     (modeline-mousable ((t (:background "white" :foreground "magenta"))))
     (modeline-mousable-minor-mode ((t (:background "white" :foreground "yellow"))))
     (region ((t (:background "white" :foreground "black"))))
     (zmacs-region ((t (:background "cyan" :foreground "black"))))
     (secondary-selection ((t (:background "blue"))))
     (show-paren-match-face ((t (:background "SlateBlue1"))))
     (show-paren-mismatch-face ((t (:background "magenta" :foreground "white")))))))

I use artist/picture-mode a lot with org-mode. It provides many tools for sketch. Among them, I use rectangle and line tools most frequently for a flow chart.

From time to time, I have to put some notes within the rectangle (node) so that the chart could be self-explanatory. In such cases, I have to count the characters to make the room and layout for the rectangles, which is very boring.

To simplify the dull job, I defined some advices (see below). Now when I choose the rectangle operation by C-c C-a r, I can start the drawing by just typing the notes and the rectangle grows by itself as I am typing. C-j (by default) is also available for multiple-line notes. In this case, however, the width of the rectangle is set by the last line.

(defvar zwz-rect-text-y-margin 0)
(defvar zwz-rect-text-x-margin 1)
(defadvice picture-self-insert (around zwz-rect-text-insert activate)
  "When using rect tool, we can draw the rectangle by inputing text.
The rectangle will surround the text by a horizontal margin = zwz-rect-text-x-margin
and vertical margin = zwz-rect-text-y-margin, and therefore the text is center-justified"
  (if (and (eq artist-curr-go 'rect) (not artist-key-is-drawing))
      (zwz-start-rect-text-input))
  ad-do-it
  (if (and (eq artist-curr-go 'rect) artist-key-is-drawing)
      (save-excursion
        (artist-next-line (1+ zwz-rect-text-y-margin))
        (artist-forward-char  zwz-rect-text-x-margin))))

(defun zwz-start-rect-text-input ()
  (if (and (> (artist-current-line) zwz-rect-text-y-margin)
           (> (artist-current-column) zwz-rect-text-x-margin)
           (or (null (char-before)) (< (char-before) 33))
           (or (null (char-after)) (< (char-after) 33)))
      (if (not (member last-command-event '(?- ?  ?| ?+ ?/ ?\\ ?= ?:)))
          (let ((last-ch last-command-event))
            (save-excursion
              (zwz-make-sure-one-line-next)
              (artist-previous-line (1+ zwz-rect-text-y-margin))
              (move-to-column (- (artist-current-column) (1+ zwz-rect-text-x-margin)))
              (artist-key-set-point))
            (setq last-command-event last-ch)))))

(defadvice picture-duplicate-line (around zwz-rect-text-newline activate)
  "for multiple-line inputs"
  (if (and (eq artist-curr-go 'rect) artist-key-is-drawing)
      (let ((left-edge (column-number-at-pos (zwz-rect-topleft-corner))))
        (forward-line)
        (zwz-make-sure-one-line-next)
        (move-to-column (+ left-edge 1 zwz-rect-text-x-margin))
        (save-excursion
          (artist-next-line (1+ zwz-rect-text-y-margin))
          (artist-forward-char  zwz-rect-text-x-margin)))
      ad-do-it))

(defun zwz-rect-topleft-corner ()
  "find the top-left corner of the rectangle.
NOTE: it does not always work in a complicated layout"
  (save-excursion
    (let ((found nil)
          (col (current-column)))
      (while (and (not found) (= (forward-line -1) 0))
        (move-to-column col)
        (while (or (member (char-after) '(?- ?=))
                   (and (= (char-after) ?+) (member (char-before) '(?- ?=))))
          (backward-char))
        (if (member (char-after) '(?+ ?/))
            (setq found t)))
      (point))))

(defun zwz-rect-bottomright-corner ()
  (save-excursion
    (let ((found nil)
          (col (current-column)))
      (while (and (not found) (= (forward-line 1) 0))
        (move-to-column col)
        (while (or (member (char-before) '(?- ?=))
                   (and (= (char-before) ?+) (member (char-after) '(?- ?=))))
          (forward-char))
        (if (member (char-before) '(?+ ?\\))
            (setq found t)))
      (point))))

(defun column-number-at-pos (&optional pos)
  (if pos (save-excursion
            (goto-char pos)
            (current-column))
      (current-column)))

(defun zwz-make-sure-one-line-next ()
  "If current line is the bottom line, a new line will open"
  (save-excursion
    (unless (= (forward-line 2) 0)
      (end-of-line)
      (open-line 1))))

Sometimes I want to make use of the space occupied by the mode-line. You can hide the mode-line by (setq mode-line-format nil). But it brings problem when you have the frame vertically splitted, as you cannot easily tell which is the current buffer. What I did is setting the height of the mode-line face very small, so that the mode-line turns into a thin line and the font is too small to be seen. Here is the code:

(defvar zwz-mode-line-height 0.8)
(defun restore-mode-line-height ()
  (set-face-attribute 'mode-line nil :height zwz-mode-line-height))
(restore-mode-line-height)
(add-hook 'after-make-frame-hook 'restore-mode-line-height)
(defun toggle-mode-line ()
  (interactive)
  (if (= 0.8 zwz-mode-line-height)
      (setq zwz-mode-line-height 0.1)
      (setq zwz-mode-line-height 0.8))
  (restore-mode-line-height))

CategoryHomepage