Posts on tag: emacs
Table of contents
Emacs viking mode
While I'm a long term emacs user (since 2000), I did not write much emacs lisp over the years. In fact I kept my config unchanged for more than a decade. Happy and lazy, you see.
But lately I stumbled upon a lot of emacs enthusiasts like Sacha Chua. And so, a couple of weeks ago, I started to re-organize my .emacs config. I turned it into an outshine file for better overview, added a version, made it portable (now I use the very same config on Windows, Linux and FreeBSD with various emacs versions). Also I added LOTs of convenient stuff to my emacs. Some are external modules I discovered, some developed myself.
One of the things I added was expand-region, which I love! But I also wanted to be able to delete stuff the same way: just press a key and delete something, press it again and delete more, press it again and delete even much more until finally the whole buffer gets deleted. So I started to implement it on my own. And I learned a lot about lisp in the process.
However, the code got bigger and bigger and I decided to put it into an extra file, but don't get me wrong: viking-mode is pretty small compared to other modes. While I was at it, I made a minor mode of it. This is not the first time, I created a mode, cisco-mode is my fabrication as well, but this time I tried to make it really good, conforming to all specs and guidelines. Finally my submission to melpa have been accepted and so here it is: my first minor mode on melpa: http://melpa.org/#/viking-mode.
The code itself is hosted on Github. And here is a small demo/screencast I made so you can see how it works:
A word about the name: I choosed this name because viking-mode just deletes things, you do not have to mark them, there's no "Are you sure?" annoyances. It is even possible to disable putting deleted stuff into the kill-ring (which would make it possible to yank it back somewhere). So - it just kills. Like a Viking, hence the name.
Migrated from Tiddlywiki to Emacs Org-Mode
I am an early adopter of TiddlyWiki, a personal wiki which runs locally in a browser. I used it for many years nearly every day at work and home. I'm so used to it, I'm unable to do my daily work without it. I even wrote a couple of plugins for TiddlyWiki and I ported it to the palm pre mobile platform.
Now that era is over, thanks to the developers of firefox. I used to use an outdated portable firefox instance at work when a couple of weeks ago the NoScript plugin has been updated. From that moment on, firefox didn't work properly anymore, so I had to update firefox as well. I did it and everything looked good. Until I clicked the "save" button in tiddlywiki - it didn't work anymore. Turns out, that the firefox developers disabled the UniversalXPConnect capability, which made it possible for local Javascripts like TiddlyWiki to access the local harddisk.
There's a plugin called TiddlyFox, which aims to close the gap, but there are several reasons why I can't use it. First, it doesn't work with older wikis. Mine was based on version 2.3 and heavily customized. I just couldn't upgrade it (and I don't know, how, anyway). So I had to use the latest TiddlyWiki version, which I don't like. Then there's the problem, that the TiddlyFox plugin just pops up firefox' "Save as..." dialogue, if you click save and the file already exists, you end up with "wiki(1).html", the next time with "wiki(2).html" and so forth, which is really annoying and impractical. Also, the very fact, that a plugin is required to save a wiki, is a no-go for me. What if the admins of my workstation decide to forbid firefox plugins? I would be fucked.
Therefore I decided to make a cut and look for another solution for note taking and organizing. I ended up with org-mode for emacs. I use emacs anyway, primarily for programming, so I'm at home already. I tried org-mode a decade ago and didn't like it. I've got to admit, I still don't really like it, but I get used to it and it'll suffice my requirements. I use org-mode only for note taking, I don't use its agenda-mode or the time and clocking keeping stuff. So, it's ok. The only thing I miss is a feature I regularly used in TiddlyWiki: click on a tag, a popup appears with all tiddlers which also have this tag, from which you can select one to open it (or jump to it, if it's already open). In org-mode you end up in the agenda if you click on a tag, which splits the window. Ok it is possible to click on a tag there which shows all matching entries but if you click on one, it opens it within the same frame as the agenda. So, in the end you've got two frames with org-mode. So far I was unsuccessfull to disable this annoying behavior, therefore I don't use the tags. Maybe some day I've got a working solution for this (e.g. an imenu with matching entries if click on a tag).
Ok, this is the script I used to convert my TiddlyWiki entries to an org-mode file: tiddlers2orgmode.pl. If you want to use it, keep in mind that it is only tested with TiddlyWiki 2.3. You may also tweak it here and there.
Finally here's the org-mode emacs config I've put together so far:
; org mode (defvar my-home "C:/Cygwin/home/tom") (defvar my-lisp (concat my-home "/.emacs.d")) (defvar my-org-file (concat my-home "/notizen.org"))(setq load-path (cons (concat my-lisp "/org/lisp") load-path)) (setq load-path (cons (concat my-lisp "/org/contrib/lisp") load-path))
(custom-set-variables ‘(org-agenda-files (list my-org-file)) ‘(org-default-notes-file (concat "/remember.org")) ‘(org-reverse-note-order t) ‘(org-remember-store-without-prompt t) ‘(org-reverse-note-order t) ‘(org-startup-indented t) ‘(word-wrap t) ‘(org-startup-truncated nil) ‘(org-columns-default-format "%80ITEM %22Timestamp %TODO %TAGS %0PRIORITY") ‘(org-mouse-1-follows-link nil) ’(org-insert-heading-always-after-current ‘t) ; new headings below current ‘(org-M-RET-may-split-line nil) ;; dont break heading with enter ‘(org-blank-before-new-entry ( ; no blank lines after headings quote ((heading . auto) (plain-list-item . auto))) ) ‘(org-agenda-restore-windows-after-quit t) ‘(org-use-speed-commands t) ; see next block for which ones ’(org-catch-invisible-edits ‘error) ; dont edit invisibles )
(setq org-speed-commands-user (quote ( (“0” . ignore) (“1” . delete-other-windows) (“2” . ignore) (“3” . ignore) (“d” . org-archive-subtree-default-with-confirmation) ; delete, keep track (“v” . org-narrow-to-subtree) ; only show current heading (“view”) (“q” . widen) ; close current heading and show all (“quit”) (":" . org-set-tags-command) ; add/edit tags )))
; ctrl-n for new entry with template (setq org-capture-templates ‘((“j” “Note” entry (file+datetree my-org-file) "* %? %^g\n %U\n %i\n")) )
(define-key global-map "\C-n" (lambda () (interactive) (org-capture nil “j”)))
; use ctrl-arrows to jump between headings (add-hook ‘org-mode-hook ( lambda () ; move heading down (local-set-key (kbd "<C-down>") ‘outline-next-visible-heading) ; move heading up (local-set-key (kbd "<C-up>") ‘outline-previous-visible-heading) ; alt-enter = insert new subheading below current (local-set-key (kbd "<kp-enter>") ‘org-insert-subheading) ; search for tags (ends up in agenda view) (local-set-key "\C-f" ‘org-tags-view) ))
(setq org-todo-keywords ‘((sequence “TODO” “STARTED” “WAITING” “DONE” “CANCELED”)))
;; todo colors (setq org-todo-keyword-faces ‘( (“TODO” . (:foreground "#b70101" :weight bold)) (“STARTED” . (:foreground "#b70101" :weight bold)) (“WAITING” . (:foreground “orange” :weight bold)) (“DONE” . (:foreground “forestgreen” :weight bold)) (“CANCELED” . shadow) ))
vimacs
Ich bin einer dieser alteingesessenen Emacsbenutzer. Ich benutze den Emacs schon seit fast 20 Jahren. Meine Config ist riesig und bei den meisten Sachen weiss ich gar nicht mehr, was das soll. Er ist mir jedenfalls sozusagen in Fleisch und Blut übergegangen.
Hin und wieder jedoch (z.b. in der Arbeit oder auf dem Server) muss ich auf den vi ausweichen. Ja, es gäbe auch eine Consolenvariante vom Emacs, aber die mag ich nicht. Da funktioniert 80% meiner Config nicht und das nervt. Heute nun habe ich festgestellt, dass ich eigentlich recht oft mit vi zugange bin. Jedesmal nervt er mich. Seit Jahren! Und im Grunde ist das meine eigene Schuld. Was bin ich auch so dumm, und quäle mich mit dem Onboard BSD-vi herum!
Da gibt es ja auch noch den Vim. Ich habe sogar eine minimalistische .vimrc seit grauen Urzeiten. Also heute habe ich mich jedenfalls mal aufgerafft, mir eine .vimrc zu erschaffen, mit der sich der Vim wenigstens ungefähr so verhält wie mein Emacs. Die Betonung liegt hierbei auf mein. Denn da ich den Emacs heftig customized habe, wird sich das von einem Stock-Emacs sicher etwas unterscheiden. Entsprechend natürlich auch die .vimrc.
Soweit ich das bis jetzt überblicke, habe ich es tatsächlich geschafft, die mir wichtigsten Features halbwegs abzubilden. Hier mal eine Liste:
- automatische Einrückung (Indentation). Wenn schon eingerückt ist, soll er in der nächsten Zeile da bleiben. Das hab ich soweit hinbekommen. Kommt natürlich nicht ansatzweise an den Emacs heran. Dort ist es z.b. so, dass ich irgendwo in einer Codezeile <TAB> drücken kann und er rückt das dann richtig ein, je nach Context im Code (d.h. Emacs "kann" Perl oder was auch immer). Im Vim geht das nicht. Man muss daher immer gleich richtig einrücken. Wenn man die Indents nachträglich ändern will, muss man das händisch machen. Es gibt da wohl auch Plugins dafür, die hab ich aber noch nicht kapiert. Kommt evtl noch.
- Leerzeichen statt echter Tabs. Geht 1a.
- Fenster aufteilen (Split Buffers). Geht auch 1a, sogar mit den gleichen Tastenkombinationen wie bei mir im Emacs, z.b. CTRL-3 horizontal splitten oder CTRL-1 Splits aufheben. Auch mit ALT-O zwischen den Buffern wechseln klappt prima.
- Schnell zwischen Buffern wechseln (ohne Splits). Im Emacs mit CTRL-X b [name|<TAB>...] bzw CTRL-X b um zum letzten Buffer zu kommen. Hab ich nicht hingekriegt. Statt dessen hab ich ein Plugin installiert, mit dem ich zumindest eine Bufferliste bekomme. Um dahin zu kommen, muss ich CTRL-X drücken. Damit kann ich leben (gerade so).
- Paragraph-weise Scrollen. Im Emacs mache ich das mit CTRL-<UP|DOWN> und dann springt der Cursor immer von einem Absatz zum nächsten (erkennt er anhand leerer Zeilen). Im Vim ist das entsprechende Commando '{' bzw '}'. Hab ich mir auf meine Tastenkombinationen gelegt und klappt ganz hervorragend. Sogar im Inputmode (Vim hat ja mehrere Modi), in dem Fall geht er nach dem Springen wieder zurück in den Inputmode. Haha!
- Wort-weise Scrollen. Ähnlich wie oben, nur mit CTRL-<LEFT|RIGHT> um ein Wort nach links oder rechts springen. Geht im Vim mit 'b' und 'w', die ich mir auf meine Kürzel gelegt hab.
- Automatisches Klammernsetzen. Ich habe ein relativ intelligentes Auto-Klammer-Plugin installiert namens Smartinput. Wirklich zufrieden bin ich damit nicht. Es bleibt immer noch viel zu viel Tipperei übrig. Zumal ich im Emacs bei bestimmten Keywords wie if, while oder foreach automatisch gleich alle notwendigen Klammern gesetzt kriege, samt richtiger Einrückung. Ich hab mir ein paar Abbreviations gebastelt, die das ungefähr nachbilden. Mehr schlecht als recht und auch nur für Perl.
- Syntaxhighlighting. Kann Vim ganz prime, obgleich ich als Emacsuser 16 Mio Farben gewöhnt bin. Im Vim krieg ich nur 16 Farben her, das ist etwas mager. Es soll wohl auch mit 256 Farben gehen, ich weiss nur noch nicht, wie. Ich benutze ein leicht angepasstes Farbschema namens Astronaut.
- *scratch*. Das ist ein im Emacs immer vorhandener Buffer, der nicht gespeichert werden muss (d.h. er fragt beim Beenden nicht wegen Speichern usw). Da kann man Notizen reinschreiben oder mal eben irgend einen Emacsmode ausprobieren. Im Vim hab ich das nachgebildet mit dem Scratch Plugin. Ich hab es allerdings nicht hinbekommen, dass der *scratch* Buffer immer da ist. Also hab ich schon, nur wenn ich dann eine Datei geöffnet habe, war der *scratch* Buffer immer der Aktuelle. Sehr nervig. Ich hab das jetzt so gemacht, dass *scratch* nur erstellt wird, wenn ich Vim ohne Datei starte. Ansonsten kann ich den auch unterwegs aufmachen mit dem :Scratch Befehl.
- Und last but not least: <CTRL-TAB>. Nutze ich im Emacs recht intensiv, damit hab ich Completion auf Wörter innerhalb eines Buffers. Also z.b. Schreibe ich "conn<CTRL-TAB>" und er macht - sofern es keine mehreren Matches gibt - "connect_server()" draus oder so. Das geht im Vim von Haus aus mit <CTRL-N> und <CTRL-P>. Hab ich unverändert so gelassen. Es erscheint bei mehreren Matches dann ein kleines Popup wo man einen auswählen kann. Im Emacs hingegen scrollt man durch die Matches, indem man erneut <CTRL-TAB> drückt. Das ist evtl. gewöhnungsbedürftig, aber was solls.
Summa Summarum kann ich jetzt also auch auf dem Server oder in der Arbeit einigermaßen komfortabel arbeiten, zwar mit Abstrichen, aber angesichts dessen, dass ich mich schon seit Jahren damit quäle, ist das jetzt ein krasser Fortschritt.
Hier ist meine Vim Config, falls jemand mal gucken möchte.
Ich habe ausserdem während meiner Forschungs- und Anpassungsarbeiten einige gute Seiten gefunden:
- usevim. Das ist ein Blog mit haufenweise Ideen, Pluginvorstellungen uvm. Sehr zu empfehlen.
- Vim Tips Wiki. Ein Wiki mit hunderten Anleitungen, Rezepten und Beispielen. Etwas schwierig dort was zu finden, ich bin aber beim Googeln mehrere Dutzend male dort gelandet :)
- Sehr interessant fand ich On sharpening the saw. Ist jetzt keine Anleitung, aber trotzdem. Vor allem die Ergänzung am Ende von einem Emacsuser: TextMate als Kreis, Vim als Dreieck und Emacs als Fraktal. Eigentlich müsste man den Emacs sogar als mehrfach-dimensionales Fraktal zeichnen, um einen ordentlichen Vergleich zu haben.
Und finally, so sieht das jetzt bei mir aus:
Update 2012-11-08:
So, einige unbefriedigende oder fehlende Funktionen hab ich doch noch beheben können:- Die Sache mit dem TAB innerhalb einer Zeile funktioniert jetzt. Wenn ich im Insertmode einfach TAB drücke, rückt er die Zeile passend ein, ganz wie im Emacs. Der entsprechende Vim Befehl ist '=^' im Normalmodus.
- Neu eingebaut habe ich noch CTRL-K: damit wird die aktuelle Zeile entfernt. Im Unterschied zu Emacs ist es dabei sogar egal, wo in der Zeile der Cursor ist. (Besser als Emacs? Gibts ja nicht!)
- Mit dem Vim Befehl "gg=G" kann man den kompletten Buffer neu einrücken (Indent). Dafür hab ich mir ein eigenes Command ":IndentBuffer" erstellt. Und ich habe herausgefunden, dass ich das mit einem Textabschnitt auch machen kann: im Visualmode ('V') Zeilen markieren und dann direkt '=' drücken.
- Ausserdem führt jetzt ein CTRL-L im Insertmode dazu, dass der Buffer so gescrollt wird, dass die aktuelle Zeile in der Mitte ist. Nutze ich im Emacs ständig. Hachmach
- Und das Farbschema hab ich nochmal nachgebessert, war zu viel Giftgrün drinnen.
Emacs im Browser?
Ich bin bekennender Emacsuser. Emacs, wer das nicht weiss, ist ein Betriebssystem. Und zwar das beste von allen. Man kann alles damit machen. Einfach alles. Wobei ich ihn am Ende doch "nur" zum Editieren verwende :)
Und hier kommt Ymacs. Das soll ein Emacs sein, der im Browser läuft, clientseitig. Und man könne damit direkt auf irgendwelche cloud-hosted Files zugreifen.
Mir erschliesst sich der Sinn nicht. Das Teil läuft also clientseitig. Genauso wie der Emacs auch. Man kann damit auf remote-Dateien zugreifen. Genauso wie mit dem Emacs auch. Man kann damit eine der ca 1 Millionen Erweiterungen laden. Genausso wie beim ... halt. Nee. Kann man nicht. Ymacs ist ja in Javascript geschrieben und nicht in Lisp.
Ich fasse also zusammen: dieses Teil kann nichts, was Emacs nicht auch könnte. Und es ist komplett inkompatibel zu Emacs. Ich könnte ihn zum Beispiel nicht dazu bringen, meine .emacs Datei zu laden. Schlicht und ergreifend hat dieses Dingens nichts mit Emacs zu tun. Es ist einfach nur ein weiterer Javascript-Online-Editor, diesmal einer, der halt das Look&Feel von Emacs emuliert. Und auch das nur in einer Einstellung. Denn tatsächlich sieht so ein Emacs natürlich bei jedem anders aus (das macht die erwähnte Datei .emacs).
Ich gebe zu, fasziniert zu sein, was manche Leute mit Krüppelsprachen wie Javascript auf die Beine stellen können. Ich finde es aber recht schade, dass die ihr Talent für solchen Unfug vergeuden.
Wer braucht sowas?