arguments.callee

初めて知ったので callee - Mozilla Developer Center を読む。

Specifies the currently executing function.

spidermonkey で試してみる。

js> function test() { print(arguments.callee); }
js> test();
function test() {
    print(arguments.callee);
}

arguments.callee allows anonymous functions to refer to themselves, which is necessary for recursive anonymous functions.

はー。なるほど。そういう場面で使うのか。

js> (function(n){return n > 0 ? n + arguments.callee(n-1) : n})(10)
55

うーん。これはすごい。

The this keyword does not refer to the currently executing function. Use the callee property to refer to a function within the function body.

js> (function(){print(this)})()
[object global]

グローバルオブジェクト?なるものが this に設定されているらしい。グローバルな名前空間をもつオブジェクトってことなのかな。
調べてみたら、下のように書いてあった。

The global object itself can be accessed by this in the global scope.

Core JavaScript 1.5 Reference - Mozilla Developer Center

てことは、普通に関数を実行する場合は、関数内での this は、グローバルスコープの this を参照してるってことなのかな。

js> a = 3
3
js> this.a
3
js> (function(){print(this.a)})()
3
js> function test() { this.a=11; print(this.a) }
js> test()
11
js> a
11

Tombloo-0.3.11 で delicious のプライベートポストができないバグを修正してみた

--- 20_model.js.orig     2008-08-06 13:12:28.000000000 +0900
+++ 20_model.js      2008-08-06 13:12:46.000000000 +0900
@@ -743,7 +743,7 @@
                                        jump        : 'no',
                                        notes       : joinText([ps.body, ps.description], ' ', true),
                                        tags        : ps.tags? ps.tags.join(' ') : '',
-                                       private     : ps.private? 'on' : '',
+                                       share       : ps.private? 'no' : '',
                                }),
                        });
                });

様々なケースでウィンドウをアクティブにする AutoHotKey の関数

他にもあるのかもしれないけれど、三つのケースでウィンドウをアクティブに。

  1. ウィンドウが表示されている場合。
  2. タスクトレイに閉まってある場合。
  3. アプリケーションが起動していない場合は起動。

タスクトレイの操作は My Scripts : AutoHotkeyを流行らせるページ を利用させていただいて解決。

#include TaskTrayIcon.ahk

ActivateOrLaunch(commandPath="") {
    SplitPath, commandPath, appName
    Process, exist, %appName%
    appPID:=errorlevel
    if (appPID <> 0)
    {
       ; there's the window
       WinGet, WIN,, ahk_pid %appPID%
       IfWinExist, ahk_id %WIN%
       {
           WinActivate
       }
       ; the window is hidden in task tray
       else
       {
           DetectHiddenWindows,On
           cnt:=Tray_GetCount()
           Loop,%cnt%{
               Tray_GetInfo(A_Index,hwnd,uid,msg,icon)
               WinGet,pn,ProcessName,ahk_id %hwnd%
               if(pn=appName){
                   PostMessage,%msg%,%uid%,0x203,,ahk_id %hwnd%
                   break
               }
           }
           DetectHiddenWindows,Off
       }
    }
    ; not running
    else
        Run, % commandPath
    return
}

引数にはコマンドのフルパスを渡す。

#^p:: ActivateOrLaunch("C:\path\to\app.exe")

YankRing.vim を導入

y でペーストした後 C-n , C-p で Yank の履歴を辿れるプラギン。

YankRing.vim : ヤンクの履歴を管理し、順々に参照、出力できるようにする ・ 名無しのvim使い を参考に導入。

起動すると以下のようなエラーダイアログがでた。

The yankring can only persist if the viminfo setting has a "!"

そこで vimrc に以下を追加。

set viminfo+=!

これで無事エラーがでなくなった。ちなみに ! の意味は、ヘルプファイルを調べてみると、

!	When included, save and restore global variables that start
	with an uppercase letter, and don't contain a lowercase
	letter.  Thus "KEEPTHIS and "K_L_M" are stored, but "KeepThis"
	and "_K_L_M" are not.  Only String and Number types are
	stored.

autocomplpop.vim で、途中でエンターを押した際、補完せず改行されるように

@@ -402,7 +402,8 @@
   echo ""
   if pumvisible()
     " a command to restore to original text and select the first match
-    return "\<C-p>\<Down>"
+    " return "\<C-p>\<Down>"
+    return "\<C-p>"
   elseif len(s:behav_rest)
     if a:first
       " In case of dividing words by symbols while popup menu is visible,

それから vimrc に以下を追加。

inoremap <expr> <CR> pumvisible() ? "<C-Y>\<CR>" : "\<CR>"