Chinaunix首页 | 论坛 | 博客
  • 博客访问: 24286
  • 博文数量: 3
  • 博客积分: 290
  • 博客等级: 二等列兵
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-11 19:52
文章分类
文章存档

2009年(1)

2008年(2)

我的朋友
最近访客

分类: LINUX

2008-09-23 14:02:33

因为有感于很多时候都是在处理文件,最近学习一下elisp,获益良多。
早就知道sawfish也是用一个elisp类似的扩展。所以边用便学吧。
emacs的info中有sawfish的doc,一来英语阅读速度太慢,二来最近时间不多,
姑且胡乱凑合这用用,没有细改,发现sawfish要配置的地方实在不太多。
一个jump-or-exec就让我方便了很多。
平时也就是emacs,urxvt,firefox,pidgin中间来逛游了。

~/.sawfishrc 的配置文件:

;;; Jian Lee 的 Sawfish 配置文件,
;;; 参考很多网上资源,这里先 表示感谢

;; 建议了解 elisp 语法后再用 emacs、sawfish 之类使用 lisp 语法扩张的程
;; 序。

;; 关于文中的一些自定义的说明,我放在配置文件最后了。

;; sawfish扩展和emacs一样多,同样通过load-path来加载,一般放到
;; ~/.sawfish/extensions 里面吧
(setq load-path (cons "~/.sawfish/extensions" load-path))

;(require 'sawmill-defaults)
;(setq menu-program-stays-running t)

;; 改变字体(setq default-font (get-font
;"-misc-simsun-medium-r-normal-*-*-120-*-*-*-*-iso10646-1"))
; (setq default-font (get-font
;"xft:simsun:encoding=iso10646-1:pixelsize=15"))

(require 'sawfish.wm.menus)
(setq my-menu
    '(("终端 Urxvt"      (system "urxvt -tn xterm &"))
      ("浏览 Firefox"    (system "firefox &"))
      ("邮件 Thunderbird" (system "thunderbird &"))
      ("聊天 Pidgin"     (system "pidgin &"))
      ("编辑 Emacs"      (system "emacs  -bg rgb:16/48/64   -fg white &"))
      ("网页 Bluefish"   (system "bluefish &"))
      ("管理 rox-filer"  (system "rox &"))
      ("图像 Gqview"     (system "gqview &"))
      ("音乐 XMMS"       (system "xmms &"))
      ("字典 Stardict"   (system "stardict &"))
      ("文本 leafpad"    (system "leafpad &"))
      ("阅读 PDF"        (system "acroread &"))
      ("远程 tsclient"   (system "tsclient &"))
      ("实验 VMware"     (system "vmware &"))
      ("取色 Gcolor2"    (system "gcolor2 &"))
      ("运行 gmrun"      (system "gmrun &"))
))


(defun popup-my-menu ()
  (interactive)
  (popup-menu my-menu))

(bind-keys global-keymap "Button1-Click1" 'popup-my-menu)
(bind-keys global-keymap "Super-F1" 'popup-my-menu)
;;(bind-keys global-keymap "Button2-Click1" 'popup-root-menu)
;;(bind-keys global-keymap "Button3-Click1" 'popup-window-menu)


;(defun one-instance-exec (prog)
;(interactive)
;(if (= (ash (system (concat "ps -C" prog)) -8) 0)
;()
;(system (concat prog " &"))
;))


;; jump-or-exec
;; 如果程序在运行,就调到当前桌面,如果没有运行,就运行它。
(require 'jump-or-exec)
(bind-keys global-keymap
           "Hyper-e" `(jump-or-exec "^yang@"
                     ,(lambda ()
                        (system "emacs &"))
                     ,(lambda (wind)
                        (display-window wind))))
(bind-keys global-keymap
           "Hyper-t" `(jump-or-exec "~"
                     ,(lambda ()
            (system "urxvt -tn xterm &"))
             ,(lambda (wind)
            (display-window wind))))
(bind-keys global-keymap
       "Hyper-f" `(jump-or-exec "Firefox"
             ,(lambda ()
            (system "firefox &"))
             ,(lambda (wind)
            (display-window wind))))
(bind-keys global-keymap
           "Hyper-r" `(jump-or-exec "Rox"
             ,(lambda ()
            (system "rox &"))
             ,(lambda ()
            (display-window wind))))
(bind-keys global-keymap
       "Hyper-p" `(jump-or-exec "Pidgin"
             ,(lambda ()
            (system "pidgin &"))
             ,(lambda (wind)
            (display-window wind))))

;; 定义窗口行为,我一般使用 Super 键
; 按住 Super和x 键,关闭当前窗口
(bind-keys window-keymap "Super-x" '(delete-window (current-event-window)))

; 移动窗口到(0,0)处
(bind-keys window-keymap "Super-l"
       '(move-window-to (current-event-window) 0 0))
; 返回当前窗口名字
(bind-keys window-keymap "Super-n"
       '(display-message (window-name (current-event-window))))
; 最大化
(bind-keys window-keymap "Super-m"
       '(move-resize-window-to (current-event-window) 0 0 1024 768))
; 右半边
(bind-keys window-keymap "Super-r"
       '(move-resize-window-to (current-event-window) 512 0 512 768))




;;; 本配置文件自定义的说明

;; 1。Super、Hyper 键绑定
;  我用xmodmap修改了键盘按键的keycode,我的~/.Xmodmap文件如下:
;keycode 37 = Control_L
;keycode 64 = Alt_L
;keycode 108 = Super_R
;keycode 105 = Hyper_R
;clear control
;add control = Control_L
;clear mod1
;add mod1 = Alt_L
;clear mod3
;add mod3 = Super_R
;clear mod4
;add mod4 = Hyper_R
;keycode 66 = Escape
;keycode 9 = Caps_Lock

;; 2。jump-or-exec 在网上down的


~/.sawfish/extensions/jump-or-exec.jl 的文件类容如下:

;;; jump-or-exec.jl --- flexible application shortcut keys (v0.1)
;; -*- lisp-mode -*-

;; Copyright (C) 2002  Free Software Foundation, Inc.

;; Author: Damien Elmes

;; This file 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 file 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:

;; To use this file, put (require 'jump-or-exec) somewhere in your local config
;; files (like ~/.sawfishrc), and then define shortcuts using it like this one,
;; for example:

;; ;; load a multi gnome terminal,
;; ;; or switch to it if it's already running,
;; ;; and load a new tab if it's currently focused

;; (bind-keys global-keymap
;;     "W-o" `(jump-or-exec "MGT"         ; window title to jump to
;;         ,(lambda ()                    ; if the window doesn't exist
;;            (select-workspace 0)
;;            (system
;;             "multi-gnome-terminal --start-factory-server --use-factory &"))
;;         ,(lambda (wind)                ; if the window is focused already
;;            (display-window wind)
;;            (synthesize-event "C-F1" wind)
;;            (synthesize-event "n" wind))))


;;; Code:

;; this function is used a bit further in, in my local config. i use it to blur
;; the line between what's running and what needs to be started, so i can hit a
;; key to load something, or jump to it if it was already running. i love
;; sawfish.
(defun jump-or-exec (re prog #!optional onfocused)
  "jump to a window matched by re, or start program otherwise."
  (catch 'return
    (let ((wind (get-window-by-name-re re)))
      (if (functionp onfocused) ; check if already focused
          (let ((curwin (input-focus)))
            (if curwin
                (if (string-match re (window-name curwin))
                    (progn
                      (funcall onfocused wind)
                      (throw 'return))))))
      (if (windowp wind)
          (display-window wind)
        (if (functionp prog)
            (funcall prog)
          (system (concat prog "&")))))))

(provide 'jump-or-exec)
;;; jump-or-exec.jl ends here


阅读(1508) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~