powershell-mode.el of emacs

2014年9月03日 00:05

简介:
更新了一下 powershell-mode 的代码
转 载请注明出处



;;
powershell-mode.el, version 0.5
;;
;; Author: Vivek Sharma (http://www.viveksharma.com/techlog)
;; Provides: Major mode for editing PS (PowerShell) scripts
;; Last Updated: 08/19/08
;;
;; Modified by Yang,Ying-chao(yangyingchao@gmail.com)
;;

;; custom hooks
(defvar powershell-mode-hook nil)

;; default mode map, really simple
(defvar powershell-mode-map
(let ((powershell-mode-map (make-keymap)))
;; (define-key powershell-mode-map "\r" 'powershell-indent-line)
(define-key powershell-mode-map "\t" 'powershell-indent-line)
powershell-mode-map)
"Keymap for PS major mode")

(defvar powershell-indent-width 4)

(defvar powershell-continued-regexp ".*\\(|[\\t ]*\\|`\\)$"
"Regexp matching a continued line (ending either with an
explicit backtick, or with a pipe)."
)

(defun powershell-continuation-line-p ()
"Returns t is the current line is a continuation line (i.e. the
previous line is a continued line, ending with a backtick or a pipe"

(interactive)
(save-excursion
(forward-line -1)
(looking-at powershell-continued-regexp)))

(defun powershell-indent-line-amount ()
"Returns the column to which the current line ought to be indented."
(interactive)
(beginning-of-line)
(let ((closing-paren (looking-at "[\t ]*[])}]")))
(if (powershell-continuation-line-p)
(progn
(while (powershell-continuation-line-p)
(forward-line -1))
(+ (current-indentation) powershell-indent-width))
(condition-case nil
(progn
(backward-up-list)
(cond ((not (looking-at ".[\t ]*\\(#.*\\)?$"))
(forward-char)
(skip-chars-forward " \t")
(current-column))
(closing-paren
(current-indentation))
(t
(+ (current-indentation) powershell-indent-width))))
(scan-error ;; most likely, we are at the top-level
0)))))

(defun powershell-indent-line ()
"Indent the current line of powershell mode, leaving the point
in place if it is inside the meat of the line"

(interactive)
(let ((savep (> (current-column) (current-indentation)))
(amount (save-excursion (powershell-indent-line-amount))))
(if savep
(save-excursion (indent-line-to amount))
(indent-line-to amount))))

(defvar pws-font-lock-keywords
`(
;; Basic keywords.
(,(rx symbol-start
(or
"default" "try" "continue" "return" "param" "finally" "catch"
"elseif" "foreach" "unction" "if" "else" "switch" "throw" "trap"
"where" "while" "for" "Default" "Try" "Continue" "Return" "Param"
"Finally" "Catch" "Elseif" "Foreach" "Unction" "If" "Else"
"Switch" "Throw" "Trap" "Where" "While" "For" "break" "Break"
"exit" "Exit"
) symbol-end)
. font-lock-keyword-face)
(,(rx symbol-start
(or
"env" "function" "global" "local" "private" "script" "variable")
symbol-end)
. font-lock-type-face)
;; Variables.
(,(rx symbol-start
(or
"Args" "ConfirmPreference" "ConsoleFileName" "DebugPreference"
"Error" "ErrorActionPreference" "ErrorView" "ExecutionContext"
"foreach" "FormatEnumerationLimit" "HOME" "Host" "Input"
"LASTEXITCODE" "MaximumAliasCount" "MaximumDriveCount"
"MaximumErrorCount" "MaximumFunctionCount"
"MaximumHistoryCount" "MaximumVariableCount" "MyInvocation"
"NestedPromptLevel" "OFS" "OutputEncoding" "PID" "PROFILE"
"PSHOME" "PWD" "ProgressPreference"
"ReportErrorShowExceptionClass" "ReportErrorShowInnerException"
"ReportErrorShowSource" "ReportErrorShowStackTrace" "ShellId"
"ShouldProcessPreference" "ShouldProcessReturnPreference"
"StackTrace" "VerbosePreference" "WarningPreference"
"WhatIfPreference" "false" "input" "lastWord" "line" "null"
"true" ))
. font-lock-variable-name-face)
(, (rx symbol-start "$" (1+ word) (0+ "_" (1+ word)))
. font-lock-variable-name-face)
;; Digital Numbers.
(,(rx symbol-start (1+ digit) (0+ "." (1+ digit)))
. font-lock-constant-face)
;; Function declaretions.
(,(rx symbol-start (group (any "f" "F") "unction")
(1+ space) (group (1+ (or word ? (any "_" "-")))))
(1 font-lock-keyword-face) (2 font-lock-function-name-face))
;; @blocks.
(,(rx line-start (* (any " \t"))
(group "@" (1+ (or word ?_)) (0+ "." (1+ (or word ?_)))))
(1 font-lock-type-face))
;; built-in comparations
(,(rx symbol-start "in"
symbol-end)
. font-lock-builtin-face)
(, (rx symbol-start "-"
(or

"and" "as" "band" "bnot" "bor" "bxor" "casesensitive"
"ccontains" "ceq" "cge" "cgt" "cle" "clike" "clt" "cmatch"
"cne" "cnotcontains" "cnotlike" "cnotmatch" "contains"
"creplace" "eq" "exact" "f" "file" "ge" "gt" "icontains"
"ieq" "ige" "igt" "ile" "ilike" "ilt" "imatch" "ine"
"inotcontains" "inotlike" "inotmatch" "ireplace" "is"
"isnot" "le" "like" "lt" "match" "ne" "not" "notcontains"
"notlike" "notmatch" "or" "replace" "wildcard")
)
. font-lock-builtin-face)
;; Builtin Functions
(,(rx (1+ (1+ word) "-") (1+ word))
. font-lock-function-name-face)
)
)

(defvar powershell-mode-syntax-table (make-syntax-table)
"Syntax table for Powershell mode")
(modify-syntax-entry ?# "<" powershell-mode-syntax-table)
(modify-syntax-entry ?' "\"" powershell-mode-syntax-table)
(modify-syntax-entry ?- "w" powershell-mode-syntax-table)
(modify-syntax-entry ?. "_" powershell-mode-syntax-table)
(modify-syntax-entry ?: "_" powershell-mode-syntax-table)
(modify-syntax-entry ?\\ "_" powershell-mode-syntax-table)
(modify-syntax-entry ?\n ">" powershell-mode-syntax-table)
(modify-syntax-entry ?_ "w" powershell-mode-syntax-table)
(modify-syntax-entry ?` "\\" powershell-mode-syntax-table)
(modify-syntax-entry ?{ "(}" powershell-mode-syntax-table)
(modify-syntax-entry ?} "){" powershell-mode-syntax-table)
(modify-syntax-entry ?[ "(]" powershell-mode-syntax-table)
(modify-syntax-entry ?] ")["
powershell-mode-syntax-table)
(modify-syntax-entry ?( "()" powershell-mode-syntax-table)
(modify-syntax-entry ?) ")("
powershell-mode-syntax-table)

(defvar powershell-imenu-expressions
'((nil "^\\(?:[fF]unction\\|Add-Class\\)\\s-+\\([-a-z0-9A-Z_^:.]+\\)[^-a-z0-9A-Z_^:.]" 1))
"alist of regexp identifying the start of powershell definitions"
)
(defun powershell-setup-imenu ()
"Installs powershell-imenu-expression."
(require 'imenu t)
;; imenu doc says these 3 are buffer-local by default
(setq imenu-generic-expression powershell-imenu-expressions)
(imenu-add-menubar-index)
(require 'which-func t)
(which-function-mode t)
)

(defun powershell-mode ()
"Major mode for editing PowerShell files"
(interactive)
(kill-all-local-variables)
(setq major-mode 'powershell-mode)
(setq mode-name "PS")
(set-syntax-table powershell-mode-syntax-table)
(use-local-map powershell-mode-map)
(setq indent-line-function 'powershell-indent-line)
(set (make-local-variable 'font-lock-defaults)
'(pws-font-lock-keywords))
(make-local-variable 'powershell-indent-width)
(set (make-local-variable 'comment-start) "#")
(set (make-local-variable 'comment-start-skip) "#+\\s*")
(set-syntax-table powershell-mode-syntax-table)
(run-hooks 'powershell-mode-hook))

(provide 'powershell-mode)









Author:yangyingchao, 2011-03-31

迎接 Gnome 3

2014年9月03日 00:05

还有 4 天时间。




Author:yangyingchao, 2011-04-01

RT 。
很期待。

折腾 Gnome3

2014年9月03日 00:04

漫长的等待之后, Gnome 3 终于如期发布了。 折腾了两天,又购入了一块独立显卡,终于把 gnome 3 成功的安装上了。

最开始的时候有点不习惯,加之集显的性能有限,总是感觉很不爽。今天加了一块独显 (HD 5750), 又费了些时间折腾驱动和配置,终于可以流畅的跑起来了,可惜很多很酷的东西没想到办法怎么抓图。


家里的机器装上了 gnome3 , gnome3 里面,只要将鼠标移到左上角, 当前桌面上所有的活动就会以缩略图的形式平铺在桌面上, 然后鼠标再轻轻一点就可以切换到所需的程序上去。很方便。

而公司里面的工作机的配置不高,且不能通过 git 获取代码,所以没有升到 gnome3 , 但在工作中使用鼠标的时候,总是习惯使然的把鼠标移动到左上角想要切换程序, 然后总是败兴而归。

刚刚折腾了一下,居然通过五行代码就可以通过鼠标的移动来调用 windowlist , 虽然不能像 Gnome3 那样看到缩略图,但也算聊胜于无吧!

代码如下:

# Show WindowList if place mouse at top left corner.
EdgeCommand Left PopupWindowList $[pointer.x] $[pointer.y]
EdgeCommand Top PopupWindowList $[pointer.x] $[pointer.y]

DestroyFunc PopupWindowList
AddToFunc PopupWindowList
+ I PipeRead `[ $[pointer.x]  -lt 30 ] && [ $[pointer.y] -lt 30 ] && echo "Windowlist (CurrentPage) NoDeskSort, SelectOnRelease, Meta_L,CurrentAtEnd, IconifiedAtEnd"`


 

Gentoo emerge 失效

2014年9月03日 00:04

Gentoo: Emerge errors after a Python upgrade?

If you encounter seemingly “strange” Python errors when emerging apps after a Python upgrade, execute:

# python-updater -v

This will rebuild packages that are broken due to the Python upgrade (Note: You can also manually emerge the packages python-updater lists)

如何选择开源许可证?

2014年9月03日 00:04

简介:
转载的文章,如何选择开源许可证。
转载请注明出处


如何选择开源许可证?

作者: 阮一峰

日期: 2011年5月 2日

如何为代码选择开源许可证,这是一个问题。

世界上的开源许可证,大概有上百种。很少有人搞得清楚它们的区别。即使在最流行的六种----GPLBSDMITMozillaApacheLGPL----之中做选择,也很复杂。

乌克兰程序员Paul Bagwell,画了一张分析图,说明应该怎么选择。这是我见过的最简单的讲解,只用两分钟,你就能搞清楚这六种许可证之间的最大区别。

下面是我制作的中文版,请点击看大图。

(完)

文档信息




Author:yangyingchao, 2011-05-03

/etc/env.d/02locale

2014年9月03日 00:04

LANG="zh_CN.UTF-8"
LC_CTYPE="zh_CN.UTF-8"

XMODIFIERS="@im=fcitx"

XIM=fcitx
XIM_PROGRAM=fcitx
XIM_ARGS="-d"

GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx

ssh 无密码登录

2014年9月03日 00:04

简介:
转载,介绍了通过私钥/公钥对来实现 ssh 无密码登录的方法。 其中,值得注意的是, client 端和 server 端的几个文件和文件夹的权限的设置。
转载请注明出处


4. SSH with Keys in a console window

This first short wil learn us how to generate a key without a passphrase, and use it in a console.

4.1 Creating A Key

When you want to use ssh with keys, the first thing that you will need is a key. If you want to know more about how this mechanism works you can have a look in chapter 3, SSH essentials. Hence there are 2 versions, we will show examples for the both of them.

4.2 Protocol version 1 key generation

To create the most simple key, with the default encryption, open up a console, and enter the following command :


[dave@caprice dave]$ ssh-keygen 

Wil output the following :


Generating public/private rsa1 key pair. Enter file in which to save the key (/home/dave/.ssh/identity): /home/dave/.ssh/identity Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/dave/.ssh/identity. Your public key has been saved in /home/dave/.ssh/identity.pub. The key fingerprint is: 22:bc:0b:fe:f5:06:1d:c0:05:ea:59:09:e3:07:8a:8c dave@caprice 

When asked for a "passphrase", we won't enter one. Just press enter twice.

The ssh-keygen program will now generate both your public and your private key. For the sake of this first simple tutorial I will call these files by their default names "identity" and the public key "identity.pub".

Your keys are stored in the .ssh/ directory in your home directory, but you can store them where ever you'd like. Good practice is to backup your keys on a floppy. If you do so, guard this floppy with your life!

* Note: specifying a key type may be mandatory on your system. In that case, skip to the version 2 key geneation process.

Lets have a look at your keys.


cd ~.ssh; ls -l -rw-------    1 dave     dave          526 Nov  2 01:33 identity -rw-r--r--    1 dave     dave          330 Nov  2 01:33 identity.pub 

The file identity contains your private key. YOU SHOULD GUARD THIS KEY WITH YOUR LIFE! This key is used to gain access on systems which have your private key listed in their authorized keys file. I cannot stress this enough, dont have your keys drifting around. Also, make sure your private key always is chmod 600, so other users on the system won't have access to it.

The file identity.pub contains your public key, which can be added to other system's authorized keys files. We will get to adding keys later.

4.3 Protocol version 2 key generation

Creating a version 2 keypair is much like creating a version 1 keypair. Except for the fact that the SSH protocol version 2 uses different encryption algorithms for its encryption. In this case we can even choos it ourselves! Huray! To find out which versions are available on your system I'd advise you to have a look in the ssh-keygen manpage.

In our example we wil create a keypair using dsa encryption. This can be done by passing the key encryption method type to ssh-keygen. This is done in the following way :


[dave@caprice dave]$ ssh-keygen -t dsa 

Which will output the following :


[dave@caprice dave]$ ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (/home/dave/.ssh/id_dsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/dave/.ssh/id_dsa. Your public key has been saved in /home/dave/.ssh/id_dsa.pub. The key fingerprint is: 7b:ab:75:32:9e:b6:6c:4b:29:dc:2a:2b:8c:2f:4e:37 dave@caprice 

Again, we will retain the default locations, and we will not use a passphrase either.

Your keys are stored in the .ssh/ directory in your home directory.

Lets have a look at your keys.


cd ~.ssh; ls -l -rw-------    1 dave     dave          526 Nov  3 01:21 id_dsa -rw-r--r--    1 dave     dave          330 Nov  3 01:21 id_dsa.pub 

The file id_dsa contains your version 2 private key.

The file id_dsa.pub contains your version 2 public key, which can be added to other system's authorized keys file.

Again, I have listed a full ls -l with permissions, make sure you have the permissions set up correctly, otherwise other users may be able to snatch it from you. It is also a good idea to give your keys a non-standard name, since it makes guessing the name of your keypair files more easy.

4.4 Placing the public key on the remote server

To be able to log in to remote systems using your pair of keys, you will first have to add your public key on the remote server to the authorized_keys (for version 1) file, and the authorized_keys2 (for version2) file in the .ssh/ directory in your home directory on the remote machine.

In our example we will assume you don't have any keys in the authorized_keys files on the remote server. (Hint: If you do not have a remote shell, you can always use your own useraccount on your local machine as a remote shell (ssh localhost))

First we will upload the public keys to the remote server :


[dave@capricedave]$ cd .ssh/ [dave@caprice .ssh]$ scp identity.pub dave@192.168.1.3:./identity.pub identity.pub    100% |*****************************************************|   526       00:00 [dave@caprice .ssh]$ scp id_dsa.pub dave@192.168.1.3:./id_dsa.pub identity.pub    100% |*****************************************************|   614       00:00 

This will place your keys in your home directory on the remote server. After that we will login on the remote server using ssh or telnet the conventional way... with a password.

When you are logged in you should create a .ssh directory, and inside the .ssh/ directory create an authorized_keys and an authorized_keys2 file and add the keys to the files. Make sure the files are not readable for other users/groups. chmod 600 authorized_keys* does the trick.

Adding the public key for version 1 works like this:


[dave@caprice dave]$ ssh 192.168.1.3 -v   [I edited out the verbose output, and entered the password]   [Remember kids, always use -v so dont try this at home :) ]  [dave@julia dave]$ mkdir .ssh [dave@julia dave]$ chmod 700 .ssh [dave@julia dave]$ cd .ssh [dave@julia .ssh]$ touch authorized_keys [dave@julia .ssh]$ chmod 600 authorized_keys [dave@julia .ssh]$ cat ../identity.pub >> authorized_keys [dave@julia .ssh]$ rm ../identity.pub 

Placing the key for version 2 works about the same :


[dave@julia dave]$ cd .ssh [dave@julia .ssh]$ touch authorized_keys2 [dave@julia .ssh]$ chmod 600 authorized_keys2 [dave@julia .ssh]$ cat ../id_dsa.pub >> authorized_keys2 [dave@julia .ssh]$ rm ../id_dsa.pub 

If you take a little peek inside your public key files, you will find it to be a bunch of crypto, separated over a couple of rules. The public key is *1 line*. It is worth to note that the entire public key file should be one line in the authorized_keys files. So using >> is preferred over copying and pasting it from one document to another. This could put line breaks in your key which makes it useless.

Either way, your keys are in place, you are ready to go to the final step and log in using your keys.

4.5 Log in using your key

To log in using your key use the ssh command. We will add -1 to make sure we are using SSH Protocol version 1.


ssh -1 -v dave@192.168.1.3 

This logs you into a system using your version 1 key.

Try it again, now for version 2


ssh -2 -v dave@192.168.1.3 

Have a look in the output of both ssh logins and you will be able to see some differences between version 1 and 2.





Author:yangyingchao, 2011-05-03

长到40岁学到的41件事

2014年9月03日 00:04

本文是从 41 Things I've Learned By 40 这篇文章翻译而来。

6月8日标志着我进入40岁。下面的是我这一路走来学到的41条建议:

41. 不要太在意别人如何看你。

40. 是人就有自尊。小心行事,不要伤害他们的自尊心。

39. 没有什么能比实干能给你更多的收获。

38. 不要嚼舌根。你所说出去的最终会以某种方式落回到你自己身上。

37. 和你了解和喜欢的人做生意。

36. 嫉妒和鄙视别人的行为不该出现在你的生活里。

35. 说“请”和“谢谢”。这会让你与众不同。

34. 需要帮助时要去请求帮助。

33. 把目标写下来是你实现梦想的重要一步。

32. 过度使用信用卡会让你未来的经济情况陷入困境。

31. 贤内助的份量重比黄金,更甚。

30. 真正的朋友会为任何能让你高兴的小事而兴奋。

29. 真正的朋友很少,要去珍惜。

28. 不存在铁饭碗。要准备一个“B计划”。

27. 善于发现别人的优点。不要老盯着别人的缺点。

26. 你开的车、你穿的衣服不代表你。不要用车和衣服或邮政编码来判断人。

25. 你是一个“品牌”。你的所作所为会影响这个牌子名声。

24. 幸运不是偶然的。

23. 年轻时就开始存钱。把你收入的10%存入养老金账户。

22. 花时间去思考你的未来。清楚什么才是成功。

21. 对孩子的爱永远不会太多!

20. 尊敬每个人。你永远不知道哪天命运会让这些轮回到你的身上。

19. 如果你不懂酒文化,就不要装懂。

18. 对待竞争者要友好。

17. 无论你的政治立场如何 —— 一生中要参加一次总统就职典礼。整个典礼都非常的酷。

16. 寻找一个导师。

15. 做一名导师。

14. 年纪越大越难保持身体的健康。但不管怎样也要保持住。

13. 并不是聪明才能成功。坚持比智慧更重要。

12. 拥有一个强有力的社交联系网是你职业生涯最强有力的保障。

11. 多读书,杂志,上网看博客和新闻。知识就是力量。

10. 写书很难。推广更难。

9. 开发你的公开演说技能。参加一个宴会主持人团体,参与锻炼两年。

8. 正直无价。

7. 拥有能够鞭策你、使你进步的朋友。

6. 如果你知道有人写了一本书,去读它。读他的书是对一个作者最大的敬意。

5. 助人最终受益的会是你自己。

4. 在你需要之前先找到一个好律师,会计,银行家。

3. 学会做饭。

2. 机会是存在的。你只需要去找到它们。

我学到的最后一件事情:

#1 – 那些真正有成就的人(金融上的,感情上的和精神上的)永远不会批评你的梦想和志向。相反,他们会想办法分享他们的经验,帮助你提高到一个新的水平。成功的人不会妒忌,他们乐见其他人有所成就。

这些建议是免费的 … 但请记住,你得到它们是因为你付出了。

祝一天好心情。

转自: http://www.aqee.net/2011/05/06/41-things-ive-learned-by-40/