Saturday, November 24, 2007

Emacs survival kit

  • ESC x  set font-lock-mode
  • Enable PHP highlighting on ubuntu (I used emacs21)
  • aptitude install emacs-snapshot emacs-goodies-el php-elisp ruby-elisp python-elisp

  • Useful commands:
    C-something = CTRL+something
    M-something = ESC then something

    C-x b : swith buffers
    C-x o : other splitted window
    C-SPACE : yank current line
    C-w : delete selected block
    M-x : grep
    M-% : replace
    C-g : quit all macro
    C-x C-c : exit emacs
    C-x C-f ~ : to know where is your .emacs
  • C-q C-j: Inserting a CR in an emacs file
    M-x whitespace-mode:  show whitespaces and tabs:

  • Macros:

  • C-x ( start recording key strokes to build a keyboard macro.
  • C-x ) stop recording key strokes to for a keyboard macro.
  • C-x e execute the keyboard macro. Only one keyboard macro can be defined at a time. This is very powerful when used in conjunction with C-u 
  • do for example: C-u 200 C-x e 

  • .emacs file

  • ;; show column numbers
    (setq column-number-mode t)
    (set-frame-font "DejaVu Sans Mono-09")

    (set-frame-font "DejaVu Sans Mono-8")
    ;; 1ASC-Liberation Mono-bold-normal-normal-*-*-*-*-*-m-0-iso10646-1

    ;; 2 spaces for tabs
    (setq-default indent-tabs-mode nil);
    (setq default-tab-width 2);

    ;; don't back up tilde files
    (setq make-backup-files nil)

    ;; show column numbers
    (setq column-number-mode t)

    ;; show matching parentesis when pressing % on a parenthesis
    (global-set-key "%" 'match-paren)
    (defun match-paren (arg)
      "Go to the matching paren if on a paren; otherwise insert %."
      (interactive "p")
      (cond ((looking-at "\\s(") (forward-list 1) (backward-char 1))
    ((looking-at "\\s)") (forward-char 1) (backward-list 1))
    (t (self-insert-command (or arg 1)))))
  • json
  • (Just run M-x beautify-json on a buffer and it will reformat it)
  • (defun beautify-json ()
      (interactive)
      (let ((b (if mark-active (min (point) (mark)) (point-min)))
            (e (if mark-active (max (point) (mark)) (point-max))))
        (shell-command-on-region b e
         "python -mjson.tool" (current-buffer) t)))
  • to compile C++ using the F7 key
  • (global-set-key [f7] 'compile)
  • Vista
  • You cannot create a .emacs file simply on Vista (problem creating a file with a name starting with a dot). What I did is download one from the net.

    • Replace in multiple files
    1. Call dired to list files in dir, or call find-name-dired if you need all subdirectories. (just select all files at this step "*")
    2. Mark the files you want. You can mark all by doing CTRL G m m .You can mark by regex by typing 【% m】. (pom.xml for example)
    3. Type Q to call dired-do-query-replace-regexp.
    4. Type your find regex and replace string. 〔➤ common elisp regex pattern
    5. For each occurrence, type y to replace, n to skip. Type 【Ctrl+g】 to abort the whole operation.
    6. Type ! to replace all occurrences in current file without asking, N to skip all possible replacement for rest of the current file. (N is emacs 23 only)
    7. To do the replacement on all files without further asking, type Y. (Emacs 23 only)
    8. Call ibuffer to list all opened files.
    9. Type 【* u】 to mark all unsaved files, type S to save all marked files, type D to close them all.
  • Debugging C++ under emacs22 
  • - M-x gdb
  • Left click on the light gray column on the C++ source to set breakpoints (gdb needs to be running)
  • Use icons at the top as debugger commands.
  • - I tried "ddd". It is on top of gdb. It is OK, but it is an external editor, independent of emacs. The ddd window is an XWindow but it is very close to what you get with gdb+emacs.
  •  .

    Wednesday, November 7, 2007

    Cell phones OS

    To summarize:

    Symbian: pretty much all Nokias, some SonyEricsson
    Windows mobile: Taiwanese HTC, HP
    Android: Linux embedded based, Google's cell phones OS
    Proprietary: IPhone, SonyEricsson

    Tuesday, October 30, 2007

    new dynamic STL list

    I always have to look back on how to do this, so here we go:

    list<string> * myList = new list<string>();

    Monday, October 15, 2007

    VIVO and Video input a VGA card ?

    I wanted to watch the video that is going out of my FreeBox HD on my PC. I thought of using the sVideo output of the FreeBox HD, and use the Peritel of the FreeBox HD for the sound.

    I know I can use streaming directly from Free, but on the direct streaming there is no TF1 or M6.

    On some PC VGA cards, you have a sVideo or DVI plug. However these are almost always video OUT only. To be able to use your VGA card for acquisition, it has to be VIVO labelled (Video In, Video Out). Just FYI.

    Wednesday, October 3, 2007

    Tuesday, August 7, 2007

    Running a simple Java program on Windows

    let's say you have:

    // Toto.java
    package com.mydomain.MyTest;
    public class Toto
    {
    public static void main (String[] args)
    {
    System.out.println("hello");
    }
    }


    then, you can create a BuildRun.bat like this:

    REM BuildRun.bat
    javac Toto.java
    copy Toto.class com\mydomain\MyTest\
    java.exe com.ltu.MyJNITest.Toto

    To get directly the execution shell file that you need to run, you can get it from Eclipse:
    http://stackoverflow.com/questions/2502518/eclipse-export-running-configuration
    .

    Saturday, August 4, 2007

    %ProgramFiles% environment variable

    %ProgramFiles% is not like the other environment variables. It is initialized by the system with the value of ProgramFilesDir at boot time, and cannot be changed after that.

    Since ProgramFilesPath value is %ProgramFiles%, it has the same value also

    "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"

    Usually, I just restart the console and all environment variables are set to their correct value. You can see the value of all environment variables by doing "set" in the Windows console. But %ProgramFiles" is initialized only at boot time.

    Creating an environment variable %ProgramFiles% from the control panel will not modify this behaviour, even after reboot.