Because `C-a C-SPC C-e M-w` just doesn't cut it, and I like playing piano, I decided to dig the web for a few helpers. I'm quite fond of the keybindings right now, let's see if they stick.
(defun duplicate-line ()
"copy the current line underneath"
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
(open-line 1)
(next-line 1)
(yank)
(move-beginning-of-line 1)
(message "TODO: restore caret position?, on original or new line?"))
(defun select-current-line ()
"Select the current line"
(interactive)
;; (end-of-line) ; move to end of line
;; (set-mark (line-beginning-position))
(beginning-of-line)
(set-mark (line-end-position))
(message "TODO: select from begin to end or end to begin ? (caret > [begin..end]/2 => beg to end. end to beg otherwise)"))
(global-set-key (kbd "C-S-d") 'duplicate-line)
(global-set-key (kbd "C-S-l") 'select-current-line)
Affichage des articles dont le libellé est elisp. Afficher tous les articles
Affichage des articles dont le libellé est elisp. Afficher tous les articles
mardi 2 avril 2013
samedi 30 mars 2013
John Wiegley induced emacs [past]discovery of the day - edebug
EmacsConf is taking place today. John Wiegley speaks about elisp environment, including elp (profiler), edebug, and many other things. So I went to read the edebug manual a bit more (as usual I read a few pages but stopped too early).
I enjoyed the trace buffer combined with [fast]trace execution mode.
Enable the trace buffer with : `M-:` (setq edebug-trace t)
Now, let's say I have this in *scratch* (.|. being the caret)
(defun fact (n)
(cond
((equal n 0) 1)
((* n (fact (- n 1))))))
.|.(fact 10)
`M-x` edebug-defun enters the elisp debugger
`T` will step through the s-exps in fast trace mode (automatically evaluate the next s-exp every N ms) and the *edebug-trace* buffer will trace the whole process nicely, resulting in this:
{ edebug-anon0 args: nil
:{ fact args: (10)
::{ fact args: (9)
:::{ fact args: (8)
::::{ fact args: (7)
:::::{ fact args: (6)
::::::{ fact args: (5)
:::::::{ fact args: (4)
::::::::{ fact args: (3)
:::::::::{ fact args: (2)
::::::::::{ fact args: (1)
:::::::::::{ fact args: (0)
:::::::::::} fact result: 1
::::::::::} fact result: 1
:::::::::} fact result: 2
::::::::} fact result: 6
:::::::} fact result: 24
::::::} fact result: 120
:::::} fact result: 720
::::} fact result: 5040
:::} fact result: 40320
::} fact result: 362880
:} fact result: 3628800
} edebug-anon0 result: 3628800
Kawaii, isn't it ?
I enjoyed the trace buffer combined with [fast]trace execution mode.
Enable the trace buffer with : `M-:` (setq edebug-trace t)
Now, let's say I have this in *scratch* (.|. being the caret)
(defun fact (n)
(cond
((equal n 0) 1)
((* n (fact (- n 1))))))
.|.(fact 10)
`M-x` edebug-defun enters the elisp debugger
`T` will step through the s-exps in fast trace mode (automatically evaluate the next s-exp every N ms) and the *edebug-trace* buffer will trace the whole process nicely, resulting in this:
{ edebug-anon0 args: nil
:{ fact args: (10)
::{ fact args: (9)
:::{ fact args: (8)
::::{ fact args: (7)
:::::{ fact args: (6)
::::::{ fact args: (5)
:::::::{ fact args: (4)
::::::::{ fact args: (3)
:::::::::{ fact args: (2)
::::::::::{ fact args: (1)
:::::::::::{ fact args: (0)
:::::::::::} fact result: 1
::::::::::} fact result: 1
:::::::::} fact result: 2
::::::::} fact result: 6
:::::::} fact result: 24
::::::} fact result: 120
:::::} fact result: 720
::::} fact result: 5040
:::} fact result: 40320
::} fact result: 362880
:} fact result: 3628800
} edebug-anon0 result: 3628800
Kawaii, isn't it ?
mardi 8 janvier 2013
Scala value class-like to php macro
;; '//' SPACE CLASS <NAME> '(' ARGS* ')'
;; class name { private args; function name(args) { $this->args = args } public get_args() { return $this->args; }(fset 'scala-to-php
[?\C-k ?\C-y ?\C-j ?\C-y ?\C-a tab delete delete delete ?\M-f ?\M-f ?\C- ?\C-e ?\C-\M-% ?\( ?\\ ?\( ?. ?* ?\\ ?\) ?\) return ?\{ ?\C-q ?\C-j ?\' ?1 backspace backspace ?\\ ?1 ?\C-q ?\C-j ?\} return ?! ?\C-r ?\{ ?\C-e ?\C-f ?\C- ?\C-e ?\C-\M-% ?, return ?\; ?\C-q ?\C-j return ?! ?\C-e ?\; ?\C- ?\C-r ?\{ ?\C-e ?\C-f ?\C-\M-% ?^ return ? ? ?p ?r ?i ?v ?a ?t ?e ? ?$ return ?! ?\C-e ?\C-j ?\C-y ?\C-a tab delete delete delete ?\M-d ?f ?u ?n ?c ?t ?i ?o ?n ?\C-e ? ?\{ ?\} ?\C-a ?\C-s ?\( ?\C-f ?\C-b ?\C- ?\C-f ?\C-s ?\) ?\C-b ?\C-\M-% ?\\ ?\( ?\[ ?\[ ?: ?a ?s ?c ?i ?i backspace backspace backspace backspace ?l ?p ?h ?a ?\" ?\] ?\] backspace backspace backspace ?: ?\] ?\] ?\\ ?+ backspace backspace ?+ ?\\ ?\) ?\C-b ?\C-e return ?$ ?\' ?1 backspace backspace ?\\ ?1 return ?y ?y ?y ?y ?\C-s ?\{ ?\C-f ?\C-b ?\C-j ?\S-\C-o ?\C-y ?\M-y ?\C-a tab ?\C-s ?\( ?\C- ?\C-a backspace tab ?\C-e backspace ?\C-a tab ?\C- ?\C-e ?\C-\M-% ?, return ?\; ?\C-q ?\C-j return ?! ?\C-e ?\; ?\C-r ?\{ ?\C-e ?\C-f ?\C- ?\C-s ?\} ?\C-p ?\C-e tab ?\C- ?\C-s ?\C-r ?\{ ?\C-e ?\C-f ?\C-\M-% ?\\ ?\( ?\[ ?\[ ?: ?a ?s ?c ?i backspace backspace backspace ?l ?p ?h ?a ?: ?\] ?\] ?+ ?\\ ?\) ?\; return ?p backspace ?$ ?t ?h ?i ?s ?- ?> ?$ ?\\ ?1 ? ?= ? ?$ backspace ?$ ?\\ ?1 ?\; return ?! ?\C-e ?\C-f tab ?\C-e ?\C-j ?\C-y ?\C-a ?\C- ?\C-s ?\( ?\C-? ?\C-s ?\C-m ?\C-r ?/ ?/ ?\C-f ?\C-a ?\C- ?\C-s ?\( ?\C-m backspace ?\C-e backspace ?\C-a ?\C- ?\C-e ?\C-\M-% ?, return ?\C-q ?\C-j return ?! ?\C-r ?\} ?\C-e ?\C-f ?\C- ?\C-s ?\} ?\C-p ?\C-e ?\C-\M-% ?6 ?\\ ?\( backspace backspace backspace ?^ ?\' backspace ?\\ ?\( ?. ?* ?\\ ?\) return ?p ?u ?b ?l ?i ?c ? ?g ?e ?t ?_ ?\\ ?1 ?\( ?\) ?\S- ?\{ ? ?$ ?t ?h ?i ?s ?- ?\M-b ?r ?e ?t ?u ?r ?n ? ?\C-e ?. backspace ?> ?$ ?\\ ?1 ?\; ? ?\} return ?! ?\C-s ?\} ?\C-m ?\C- ?\C-r ?c ?l ?a ?s ?s ?\C-m tab])
// class User(name,login,password)
===
class User{
private $name;
private $login;
private $password;
function User($name,$login,$password) {
$this->$name = $name;
$this->$login = $login;
$this->$password = $password;
}
public get_name() { return $this->$name; }
public get_login() { return $this->$login; }
public get_password() { return $this->$password; }
}
/tmp/kbd-macro.el (END)
I should write an keybindings expander and a literal reducer to make this bearable </lisp>
Inscription à :
Articles (Atom)