Monthly Archives: June 2011

有用的emacs快捷键

  • 列编辑C-x r t yourstring RET (参见How to do select column then do editing in GNU Emacs ?)
  • 记录当前位置到register中 C-r SPC (需安装better-registers.el,且要注释掉其中对快捷键’C-x r’的占用)
  • 跳转至某register, C-j (需better-registers.el)
  • Save frame configuration to register, C-r f (要求同上)
  • Comment current line, M-; (需qiang-comment-dwim-line)
  • Visit the next/previous error message, M-g M-n/M-p
  • find-tag/pop-tag-mark, M-./M-*
  • M-x lgrep/rgrep, grep CWD only or all sub-directories
  • M-x visit-tags-table, give you choice on multiple tags table
  • M-x org-timer-set-timer, C-c C-x ;, set count down timer
  • M-x org-mark-subtree, 选中org-mode中的subtree

Perforce Tip: how to apply my default change to the release branch

Reasons I need this hack

  • Our current project used mix platforms (WIN64/Linux64), so the file path contains backward slash `\`.
  • My p4 CLI program is from Windows installer because Cygwin version has the slash issue.
  • Windows version of p4 has no such issue under Cygwin if we only feed it relative path.

How to?

Create the patch,

p4 diff -du -db main-branch/... > ~/mywork.patch

Go to the work directory of release branch.

cd dir-release-branch/

`p4 edit’ the files I want to patch under release branch. Please note,

  • `lsdiff’ is from the package `patchutils’.
  • `nosl’ will strip the backward/forward slashes. It’s written by me.
cat ~/mywork.patch|lsdiff|nosl 5|p4 -x - edit

Patch the files and DONE!

patch -p5 < ~/mywork.patch

Here is the source code of nosl. I put it in my .bashrc

nosl ()
{
    if [ -z "$1" ]; then
        echo "Usage: echo /hello/world|nosl num";
        echo "strip num leading slashes";
    else
        perl -pe "\$n=$1;while(\$n>0){ \$_=~ s/[^\\\\\\/]*[\\\\\\/]+//;\$n--; }";
    fi
}

BTW, you could avoid all the trouble of Perforce by switching to Git.