emacs with perl auto completion

I have to admit that I am programming again. Yes, again, after five or six years. Again, I am still programming perl, still under emacs. Fortunately, the language doesn’t change a lot, so do emacs.

Ok, of course emacs, but we need do some modification to make it as a good IDE. There are two auto completion modes I can find on the net, let’s talk about the details.

  1. autocomplete
    This is a Japanese designed model which has popup menu to complete the keywords. Even the project was stop 3 years ago, but the mode is still useful.
    http://emacswiki.org/emacs/AutoComplete
    After reading hundreds documents through the Google and put around thirty some lines into the .emacs file, I still can’t make it work. Eventually I had to get back to read the official manual and just got a hint. It was only a hint instead of a solution, but it helped. The solution is easy, just extract the zip file into site-lisp folder, normally it’s under .emacs.d folder. Then put the following lisp into the .emacs:
     (add-to-list 'load-path "~/.emacs.d/site-lisp/auto-complete-1.3.1")
     (require 'auto-complete-config)
     (add-to-list 'ac-dictionary-directories "~/.emacs.d/site-lisp/auto-complete-1.3.1/dict/")
    
     (ac-config-default)

    Until now, it won’t work. You still need a perl dictionary which is a plain text reserved keywords list. The key point is how to name the file. The package already has several dictionaries under its own dict folder and named as css-mode, ruby-mode, and etc. NONE of them will work! You have to make a copy of the dictionary files into relative extension names. For example, python-mode file has to be a file named as "py". Perl dictionary isn’t the default and has to follow the file naming rule, I prepared a pl file for you, just save as it to dict folder.

  2. perl-completion

    This one isn’t as fancy as the above, but it’s much more useful for a programmer. It also lists the keywords but is at the bottom message area. It can do some sort of syntax analyst that’s why I prefer it. This one need three modes:

    http://www.emacswiki.org/emacs/PerlCompletion

    http://www.emacswiki.org/emacs/anything.el

    http://www.emacswiki.org/emacs/anything-match-plugin.el

    and need the following to the .emacs:

    (add-hook 'cperl-mode-hook
              (lambda()
                (require 'perl-completion)
                (perl-completion-mode t)))

    It won’t automatically load up, so you have to ‘M-x cperl-mode’ to active it.

  3. When use those together, autocomplete doesn’t require the dictionary file. Instead, the keywords list, aka the autocomplete source, will be provided by perl-completion. And following to the .emacs, the code in 1 and 2 has to be in consequence and 3 also.

    (add-hook  'cperl-mode-hook
               (lambda ()
                 (when (require 'auto-complete nil t) ; no error whatever auto-complete.el is not installed.
                   (auto-complete-mode t)
                   (make-variable-buffer-local 'ac-sources)
                   (setq ac-sources
                         '(ac-source-perl-completion)))))
    
    

How to avoid *.*~ backup files in emacs

Following coding in .emacs can change the default backup folder
 
(setq backup-directory-alist '(("." . "~/.emacs.d/backup"))
  backup-by-copying t    ; Don't delink hardlinks
  version-control t      ; Use version numbers on backups
  delete-old-versions t  ; Automatically delete excess backups
  kept-new-versions 20   ; how many of the newest versions to keep
  kept-old-versions 5    ; and how many of the old
  )

New Wubi IME for emacs

This is just a modified Wubi IME for emacs, it’s under GPL. Originally, it’s from http://daiyuwen.freeshell.org/gb/wubi/wubi.html I modified wubi-rules.el file and added 51,473 words to it.

Also, I added a full-width, Quanjiao, space  by pressing “=”.

This IME can use M-x wubi-toggle-quanjiao-banjiao to toggle Quanjiao and Banjiao, also can use M-x wubi-add to add personal word phase.

The package can be download here, you can load Wubi by adding the following code into .emacs

(add-to-list 'load-path "<destination>/wubi")
(require 'wubi)
(wubi-load-local-phrases) ; add user's Wubi phrases
(register-input-method
 "chinese-wubi" "Chinese-GB" 'quail-use-package
 "WuBi" "WuBi"
 "wubi")
(setq default-input-method "chinese-wubi")

mac下的emacs meta键设置

  在用Windows的时候,Windows的104键盘,左下角是Ctrl键、Windows键和
Alt键。所以我习惯将Alt设成Meta键。如果在Linux下,也用Windows键盘,那么
alt键也是meta。

  然而到了Mac下面,苹果的键盘左下角,依次是Ctrl键、Options键和
Command键,其中Options键的键值和Alt是一样的,所以本来习惯的左下角第三个
键是Meta变成了第二个,很不习惯

  如下的一段就是解决这个问题的,放在.emacs中即可,设置后command键变
成meta键,依然是左边第三个。

(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)

mac下用emacs上gtalk聊天

  好了,一鼓作气,再来玩一个新花样:用emacs接gtalk聊天,变态吧?

  查了一下,现成有jabber.el,关键就是设置了。老规矩,下载下来,放到~/.emacs.d/site-lisp中去。jabber.el其实不是一个文件,而是一整个包,缺省的解压是在一个带版本号的目录下,我改成了~/.emacs.d/site-lisp/emacs-jabber,所以在.emacs中,加了这么一句:

(add-to-list 'load-path "~/.emacs.d/site-lisp/emacs-jabber")

  然后是这么几句:

(require 'jabber-autoloads)
(setq jabber-account-list '(
                            ("yuleshow@gmail.com"
			      (:password."*************")
                              (:network-server . "talk.google.com")
                              (:port . 443)
                              (:connection-type . ssl))
                            ))

  好了,用M-x jabber-connect连接服务器,然后用M-x jabber-chat-with聊天吧,爽去吧!

  目前还有几个很小的问题,第一,虽然上面设置了用户名和密码,但是连接时
还要输一遍;第二,如何新开几个窗口(我指自动的,其实苹果下很方便地可以用
commnd-n开新的出来),省得在buffer之间切换了。

  上两张图,让大家伙儿见识见识:

———华丽丽的分割线———

  再补充一句,如果要在Windows下使用,需要安装一个GNUTLS(http://josefsson.org/gnutls4win/)来建立ssl,只要安装一下即可。

用emacs发布wordpress博客,详细解说

这是我的第一篇(其实是第二篇啦,今天下午设置时,抑制不住兴奋,当场就
发了一篇)用emacs发表的wordpress博客,到目前为止,我一点头绪也没有,大家和我一起慢慢来探索就是了。先说一下环境:

Mac OS X version 10.6.5
GNU Emacs for Mac OS X version 23.2, http://emacsformacosx.com

emacs 解压后无需安装,将app拖入applications运行即可,现在的环境变量如下:

home: ~/
.emacs: ~/.emacs
.emacs.d: ~/.emacs.d

我用的是英文版MAC OS,外挂FIT输入法,目前emacs能够打开中文文件名档,也可以写中文并存储,唯一会出现乱码的情况是m-x shell,而m-x dired则没有问题,留待以后研究。

然后我参考了这篇文章,http://emacser.com/weblogger.htm,在这里也顺便介绍一下”emacs中文网”, 并且感谢一下vvoody(vvoody.org)。

要在emacs下发表wordpress,需要weblogger.el和xml-rpc.el,我从vvoody那里下载了来,打了一个包,放在这里

需要做的事情是在~/.emacs.d下建立一个site-lisp目录,并且将两个lisp文件放入,并且在.emacs中加入一句(require ‘weblogger),然后我重新启动了一下emacs,出来的结果是:

Warning (initialization): An error occurred while loading `/Users/yuleshow/.emacs’:

File error: Cannot open load file, weblogger

看来虽然系统自动建立了~/.emacs.d目录,却不能将之设定为缺省的load目录,还需要手中设置,再来改几句话。

———-华丽丽的分隔线—————–

昨天写到这里,就僵住了,emacs 死活不肯调用 weblogger.el,很明显是路径的问题,查了一些资料,莫衷一是,各种稀奇古怪的办法都有,有人在.emacs里用了十几行;甚至有人用了MAC下的Plist Edit Pro来改.plist文件了。

第一感觉就是他们都走远了,但是由于小女住院,我医院家中两头跑,也没来得及细研究,糊里糊涂地就睡下了。今天到了办公室,找出当年买的GNU emacs manual来,其实这本东西就是在线手册,我只是当年作为一个emacs爱好者,以一种浪费木材的方法来表达对Richard Stallman的敬意罢了。说来好玩,每当我碰到难题时,只要祭出此书,哪怕一页也不翻,问题都能迎刃而解。

说出来,其实大家都会笑的,只要这么一句就行了(加在.emacs)中:

(add-to-list ‘load-path “~/.emacs.d/site-lisp/”)

接下来的事,就相当容易了,首先,需要使用M-x weblogger-setup-weblog命令来配置wordpress,这里需要注意的一点是,Server Endpoint(URL)缺省的格式是http://www.openweblog.com/xmlrpc/,而在设置wordpress时,要设成wordpress目录下的xmlrpc.php,有些朋友用根映射的办法把子目录映射到了根目录,此时要填上子目录的路径,比如我就是: http://www.yuleshow.com/wordpress/xmlrpc.php,然后emacs会连到你的服务器,接下来填入用户名和密码,最后一步则是在Name this configuration时给这个wordpress起个名,特别是在你有许多blog的时候。

然后,就是发表博客了,每回新打开emacs后,要选定发表到哪一个博客上,命令是M-x weblogger-select-configuration,当只设置了一个博客时,emacs会选择唯一的那个。

那么,就写篇新的文章吧,命令是M-x weblogger-start-entry,然后界面就
变成了这样:

Subject: 用emacs发布wordpress博客,详细解说
Permlink:
Tags: emacs wordpress
Categories: emacs wordpress
From: Yule Show
Newsgroup: 梅玺阁之幸福生活
Message-ID: <3654/1@www.yuleshow.com>
–text follows this line–

好了,到了这里,谁都懂了,写完之后,用C-x C-s来保存(同时发表),或者
用C-x C-c来直接发表。

最后,再提醒一句,用M-x weblogger TAB可以列出所有的命令。

———-

另外,发现了一个小问题,在用了M-x weblogger-fetch-entry修改已经在博客上的文章时,每fetch一次,文章的标题就会被重复一次,慢慢再研究。