仅仅是一个测试文章,请忽略。若对用emacs写博客
感兴趣,可以参考这里

近日开发一个小工具,用到了Google API,在OAuth认证的问题上遇到个小问题,问题虽小并已经解决,但其中折射出的道理却是很大并且值得记录于此供日后加勉。
问题是这样的:
所开发的小工具需要通过OAuth认证获得用户多于一种服务的读写权限,这个需求应该很常见,问题也并不复杂。可以从google api官方文档看到如下说明:
scope
A required parameter in the Request URL. Your gadget will only be able to access data from the scope(s) used in this parameter. In this example, the gadget will access Blogger and Calendar data. A gadget can request data for a single scope or multiple scopes (as this example does).
所指example中对应的部分为:
scope=http://www.blogger.com/feeds/%20http://www.google.com/calendar/feeds/
至此,应该感觉不会有问题,但具体实施时遇到了情况,按照文档中的说明却无法成功获得用户多个权限,我的代码是这样写的:
'scope': ‘http://www.blogger.com/feeds/%20http://www.google.com/calendar/feeds/’,
乍一看没有问题,但就是不行!

问题出在哪里?就在一个小小的空格(%20)上,按照我的写法,正确的方式应该这样:

'scope': ‘http://www.blogger.com/feeds/ http://www.google.com/calendar/feeds/’,
这个问题很低级,但很容易被忽视和碰到。

从进入和离开决这个问题的过程中,总结以下几点感受:

官方文档很重要

第一手的官方文档是学习技术、知识最好的资料和教科书,错误相对最少,覆盖最全面,表达相对最准确。

查看文档要仔细

对于重要的文档,一个字一个字的看,看明白,仔细、仔细、再仔细,多仔细都不过分。

emacs自动补全功能的nesC扩展

nesC是一个小众开发语言,在网上没看到有现成的自动补全扩展,基于牛人MATSUYAMA Tomohiro开发的自动补全扩展,我比葫芦画瓢写了该扩展。
存放于此,算是做个备份,有需要者尽管拿去用。
本人对emacs和elisp也是新手,略知皮毛,欢迎交流和指点!
代码如下:


;;; auto-complete-nesc.el --- auto-complete-mode extension for nesC

;; Copyright (C) 2008, 2009 baaluck

;; Author: baaluck <baaluck@gmail.com>
;; Keywords: auto-complete, nesc
;; Version: 0.1

;; This program 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 3, or (at your option)
;; any later version.

;; This program 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 this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.

;;; Commentary:
;;
;; Some extension for auto-complete-mode.
;;
;; Below are commands you can use:
;;
;; `ac-source-nesc'
;; Provide a completion for nesC.
;; Enjoy!

;;; Qualification:
;;
;; This extension can work properly on GNU Emacs 22 or higher.

;;; Installation:
;;
;; Put auto-complete-nesc.el to your load-path.
;; The load-path is usually ~/elisp/.
;; It's set in your ~/.emacs like this:
;; (add-to-list 'load-path (expand-file-name "~/elisp"))
;;
;; And write following code into your .emacs.
;;
;; (require 'auto-complete-nesc)
;; (setq ac-modes
;; (append ac-modes
;; '(
;; nesc-mode
;; )))

;;; Change log:
;;
;; 2010/01/28
;; First released.
;;

;;; Acknowledgements:
;;
;;
;;

;;; TODO
;;
;;
;;

;; Require
(require 'auto-complete)

;;; Code:
(defconst nesc-keywords
(sort (list
;; nesC keywords------------------------------------------------------
"as" "atomic" "async" "call" "command" "component" "components" "configuration" "event" "generic" "implementation" "includes" "interface" "module" "new" "norace" "nx_struct" "nx_union" "post" "provides" "signal" "task" "uses" "abstract" "extends"
;; nesC external type-------------------------------------------------
"result_t" "bool" "int8_t" "uint8_t" "int16_t" "uint16_t" "int32_t" "uint32_t" "int64_t" "uint64_t" "nx_int8_t" "nx_int16_t" "nx_int32_t" "nx_int64_t" "nx_uint8_t" "nx_uint16_t" "nx_uint32_t" "nx_uint64_t" "nxle_int8_t" "nxle_int16_t" "nxle_int32_t" "nxle_int64_t" "nxle_uint8_t" "nxle_uint16_t" "nxle_uint32_t" "nxle_uint64_t"
;; others-------------------------------------------------------------
;"lll"
) #'(lambda (a b) (< (length a) (length b)))))

(defvar ac-source-nesc
'((candidates
. (lambda ()
(all-completions ac-target nesc-keywords))))
"Source for nesC keywords.")

(add-hook 'nesc-mode-hook
(lambda ()
(make-local-variable 'ac-sources)
(setq ac-sources '(
ac-source-nesc
ac-source-words-in-buffer ;add extra-source if you need
))))
;; ---------------------------------------------------------
(provide 'auto-complete-nesc)

Emacs & nesC

由于项目需要,接触到nesC语言。很自然希望自己常用的emacs编辑器能够支持nesC的.nc文件。

多亏了google搜索引擎的优秀与emacs编辑器本身的强大,虽然相比c++, java等主流编程语言,nesC语言的使用者应该不多,同时使用nesC和emacs编辑器的牛人更是少之又少,但是的的确确存在nesC-mode,并且还是官方的,着实让我内流满面!

为了表达我对emacs神器的敬仰与开发nesC-mode的牛人David Gay的感谢,同时记录一下nesc-mode的安装配置过程以方便以后查看。故书写此文——如何在emacs下使用nesC模式。

1、获取nesC-mode源码

去nesC compiler在sourceforge上的官方站点下载最新版本(成文时的版本为:nesc-1.3.1.tar.gz)的软件包。解压缩后可以在”nesc-1.3.1/tools/editor-modes/emacs”文件夹看到nesC-mode的源码(nesC除了提供emacs编辑器的扩展,还提供了gedit, kde和vim的相应模式)。

2、安装nesC mode

-复制nesC-mode源码(*nesc.el)到emacs的LoadPath,我自己的LoadPath是
“~/.emacs.d/elisp/”

-将下面的代码加入.emacs文件:

(setq load-path (cons (expand-file-name "put your loadpath here") load-path))
(autoload 'nesc-mode "nesc.el")
(add-to-list 'auto-mode-alist '("\\.nc\\'" . nesc-mode))

Hello World!

经过几天的安装与调试,我的个人独立博客『baaluck•修行』主体已经成形。特以此文纪念博客诞生!此时这里还是一张白纸,不过我相信随着时间的流逝,这里必将丰富多彩!

© 2010 baaluck•修行 Suffusion WordPress theme by Sayontan Sinha