Search This Blog

Loading...

Saturday, April 11, 2009

comint-within-quotes in emacs

the function comint-within-quotes tells whether the cursor in quotes by counting the number of quotes from a start position to an end position.
but it can not handle an empty string like this: ""
it counts the first quote but ignores the second one.
and the single quote ' in common lisp has it's special using other than quoting something,oh,well,I mean it quotes something not with a pair but a single one.
so I hope I can have the function count only double quotes when editing common lisp and this is what I've defuned:

(defun comint-within-single-quotes (beg end)
(let ((countsq (comint-how-many-region "\\(\\=\\|[^\\\\]\\)\'" beg end)))
(= (mod countsq 2) 1)))

(defun comint-within-double-quotes (beg end)
(let ((countdq (comint-how-many-region "\\(\\=\\|[^\\\\]\\)\"" beg end)))
(= (mod countdq 2) 1)))

(defun* comint-within-quotes-2 (beg end &key (quotes :both))
(case quotes
(:both (comint-within-quotes beg end))
(:single (comint-within-single-quotes beg end))
(:double (comint-within-double-quotes beg end))))

Friday, September 12, 2008

ipython in emacs with dark background

I use a black bg color theme in emacs,while ipython outputs like this by default:

 
well,some part of the output is black,it sucks
after a travel in the source code of ipython.el and python-mode.el,I found that ipython.el add a "-color lightbg" to command args when start ipython by default,as following:


(unless (member "-colors" py-python-command-args)
(setq py-python-command-args
(nconc py-python-command-args
(list "-colors"
(cond
((eq frame-background-mode 'dark)
"Linux")
((eq frame-background-mode 'light)
"LightBG")
(t ; default (backg-mode isn't always set by XEmacs)
"LightBG"))))))

so I can either modify the py-python-command-args variable or frame-background-mode variable to stop it sucking.
I choose the latter one.
 
BTW:both ways the variable must be set before ipython.el is loaded,for the code above is runned while loading rather than in a function which runned later.

Friday, July 25, 2008

ULK note (1):Segment in linux

According to ULK,linux uses segmentation in a very limit way,namely,linux uses 4 segments,two for user mode and two for kernel mode.Linux also defines macros as segment selectors of these 4 segments:__USER_CS,__USER_DS,__KERNEL_CS,__KERNEL_DS.

I lookup the definition in include/asm-i386/segment.h(crash here for details),let's take a look at __USER_CS and __KERNEL_CS:

#define GDT_ENTRY_DEFAULT_USER_CS 14
#define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS * 8 + 3)

#define GDT_ENTRY_KERNEL_BASE 12
#define GDT_ENTRY_KERNEL_CS (GDT_ENTYY_KERNEL_BASE + 0)
#define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)

well,14(GDT_ENTRY_DEFAULT_USER_CS) is the user data segment descriptor's offset in GDT.

8 is the length of segment descriptor,easy to understand,huh(it's my first thought)?But what is the "+ 3"?

In fact,8 is (1000) in binary,so multiplying 8 left shift GDT_ENTRY_DEFAULT_USER_CS by 3 bits.aha!It's the TI and RPL fields in segment selector!so what the red "+ 3" turns out:it means this segment is in GDT(TI cleared) and it's in user mode(RPL=11).

Similar to __USER_CS,RPL of __KERNEL_CS is set to 00 to indicate that the segment is in kernel mode,so nothing needs to be added.