(defun zs-copy-current-file-name-to-system-clipboard (&optional full-path-p)
"copy, if the current buffer accesses a file, the name or file path(given a
prefix argument) to the system clipboard(if under X) and append to the killing
ring."
(interactive "P")
(if (buffer-file-name)
(if full-path-p
;; (x-select-text (buffer-file-name))
(kill-new (buffer-file-name))
;; (x-select-text (file-name-nondirectory (buffer-file-name)))
(kill-new (file-name-nondirectory (buffer-file-name)))
)))
2009-07-19
[Small Pieces In Emacs] Copy the name or path of the current buffer's file, if any.
2008-12-26
a coarse classification of naming conventions(patterns) within the Emacs ecosystem
syntactic : char, word, line, sentence, paragraph, region, page,
sexp, list, defun,
emacs-specific : register, rect, buffer, mode, frame, window,
font : face, font
filesystem : file, dir,
location and direction : beginning, end, forward, backward, next, previous, up, down,
action : search, goto, kill, delete, mark, insert, yank, fill, indent, find, view, describe, change, set,
misc : case, what, default.
2008-12-16
a native simple wc in Emacs Lisp
I googled "count words emacs" and read several articles, "Counting words in Emacs" and "Emacs Tip: Word counting with a regular expression". The first uses a loop and a regular expression to count only words in a region, and the latter uses the emacs built-in function "how-many" to count words in the whole current buffer. So I combined them to the following `wc` function which count in the whold buffer when no region is active and in the region otherwise.
(defun wc ()
"a simple mimic of the linux command `wc`"
(interactive)
(message "Word count: %s"
(how-many "\\w+"
(or (and (region-active-p) (region-beginning)) (point-min))
(or (and (region-active-p) (region-end)) (point-max)))))
2008-10-13
A great tutorial to Emacs editor
That tutorial is available at http://www.gnu.org/software/emacs/tour/ .
I learned some new features, such as `wdired-change-to-wdired-mode' which enables one to change filenames(use C-x C-s or C-c C-c to save, or C-c C-k to abord changes). Also, that tutorial reminds me how to move in units of sentences(`M-a', `M-e', still not used to the former, though); how to stop isearch at the place found(namely, leaving point there) by press the
BTW, I have bound `C-2' to call the command `set-mark-command`, so it unifies the set mark action in both the X system and the console environment: I just have to type `C-2', though in X it's interpreted as Ctrl+2 but in console environment as Ctrl+@.
I learned some new features, such as `wdired-change-to-wdired-mode' which enables one to change filenames(use C-x C-s or C-c C-c to save, or C-c C-k to abord changes). Also, that tutorial reminds me how to move in units of sentences(`M-a', `M-e', still not used to the former, though); how to stop isearch at the place found(namely, leaving point there) by press the
key.
BTW, I have bound `C-2' to call the command `set-mark-command`, so it unifies the set mark action in both the X system and the console environment: I just have to type `C-2', though in X it's interpreted as Ctrl+2 but in console environment as Ctrl+@.
2008-10-01
Let emms to remember the last directory
It causes a little trouble to me each time to find the target directory in directory when using the fantastic Emacs Multimedia System(emms), because I have to start to locate the target directory from the default directory which is specified in `emms-source-file-default-directory'(BTW, I bound the key `' to `emms-play-find').
So I'm wondering why not to make emms remember the last target directory? Then it's easy to switch other directories around the current targeted one(I tend to listen to albums with the same genre). So after digging into emms's source code, I changed the definition of `emms-play-find' a little(in fact that function is defined via a macro called `define-emms-source'):
And that's it. After reloading emms, use `emms-play-find' to find a target directory, it simply remembers that directory which ease the next operation for me.
And here is the patch file:
So I'm wondering why not to make emms remember the last target directory? Then it's easy to switch other directories around the current targeted one(I tend to listen to albums with the same genre). So after digging into emms's source code, I changed the definition of `emms-play-find' a little(in fact that function is defined via a macro called `define-emms-source'):
;;;###autoload (autoload 'emms-play-find "emms-source-file" nil t)
;;;###autoload (autoload 'emms-add-find "emms-source-file" nil t)
(define-emms-source find (dir regex)
"An EMMS source that will find files in DIR or
`emms-source-file-default-directory' that match REGEX."
(interactive (let ((directory-name (emms-read-directory-name "Find in directory: "
emms-source-file-default-directory
emms-source-file-default-directory
t))
(regex (read-from-minibuffer "Find files matching: ")))
(setq emms-source-file-default-directory directory-name)
(list directory-name regex)))
(mapc (lambda (file)
(unless (let ((case-fold-search nil))
(string-match emms-source-file-exclude-regexp file))
(emms-playlist-insert-track
(emms-track 'file file))))
(emms-source-file-directory-tree dir regex)))
And that's it. After reloading emms, use `emms-play-find' to find a target directory, it simply remembers that directory which ease the next operation for me.
And here is the patch file:
--- /tmp/emms-3.0/emms-source-file.el 2007-06-30 00:16:24.000000000 +0800
+++ elisp/emms/emms-source-file.el 2008-10-01 14:14:40.000000000 +0800
@@ -150,12 +150,13 @@
(define-emms-source find (dir regex)
"An EMMS source that will find files in DIR or
`emms-source-file-default-directory' that match REGEX."
- (interactive (list
- (emms-read-directory-name "Find in directory: "
- emms-source-file-default-directory
- emms-source-file-default-directory
- t)
- (read-from-minibuffer "Find files matching: ")))
+ (interactive (let ((directory-name (emms-read-directory-name "Find in directory: "
+ emms-source-file-default-directory
+ emms-source-file-default-directory
+ t))
+ (regex (read-from-minibuffer "Find files matching: ")))
+ (setq emms-source-file-default-directory directory-name)
+ (list directory-name regex)))
(mapc (lambda (file)
(unless (let ((case-fold-search nil))
(string-match emms-source-file-exclude-regexp file))
2008-01-08
Finally the annoying "elseif" indentation bug is solve in php-mode
I browsed emacswiki this morning and found that there is another new version of php-mode. With the hope that this version will solve the annoying and ugly "elseif" indentation bug in my emacs, which is like("_" stands for One SPACE here)
I immediately downloaded that new mode file and installed it, later added several tunings:
Now, time to try it!! Very lucky, that bug has now disappeared! See this screnshot:

// also, I add "print_r"to the constant php-keywords in php-mode.el to make it appears just the same as "echo":
if($true)
__{
__}
elseif($false)
{
}
else
___{
___}
I immediately downloaded that new mode file and installed it, later added several tunings:
(add-hook 'php-mode-hook
'(lambda () (define-abbrev php-mode-abbrev-table "ex" "extends")))
Now, time to try it!! Very lucky, that bug has now disappeared! See this screnshot:

// also, I add "print_r"to the constant php-keywords in php-mode.el to make it appears just the same as "echo":
(defconst php-keywords
(eval-when-compile
(regexp-opt
;; "class", "new" and "extends" get special treatment
;; "case" and "default" get special treatment elsewhere
'("and" "as" "break" "continue" "declare" "do" "echo" "else" "elseif"
"endfor" "endforeach" "endif" "endswitch" "endwhile" "exit"
"extends" "for" "foreach" "global" "if" "include" "include_once"
"next" "or" "print_r" "require" "require_once" "return" "static" "switch"
"then" "var" "while" "xor" "private" "throw" "catch" "try"
"instanceof" "catch all" "finally")))
"PHP keywords.")
2007-10-13
emacs cvs unicode branch now supports multi-tty!
On 3rd, Oct, I saw on the emacs developing mailing list that RMS was calling for a merging of multi-tty in to emacs's unicode branch. Since then I have always been longing for that merging.
And now, it has come true! This morning I updated the source code and found a lot of patches and updates. I took a look at the src/Changelog.unicode, found there is a item saying:
I guess the multi-tty has been already merged successfully!
So I took a hurry to compile the newest src codes. And you can guess that, it succeeds! Now I'm running it.
PS: Does anyone knows about how to customize a single frame's color-theme?
And now, it has come true! This morning I updated the source code and found a lot of patches and updates. I took a look at the src/Changelog.unicode, found there is a item saying:
2007-10-12 Stefan Monnier
Fix up multy-tty merge.
I guess the multi-tty has been already merged successfully!
So I took a hurry to compile the newest src codes. And you can guess that, it succeeds! Now I'm running it.
PS: Does anyone knows about how to customize a single frame's color-theme?
2007-09-27
Trackerd in ubuntu gutsy causes emacs to repond slowly when saving files
The slow repondence of emacs saving files is really conspicuious when trackerd(tracker's daemon) is running in the background. After I kill the trackerd with the command "killall -9 trackerd", emacs just acts so briskly.
I think the possible reason is that trackerd is watching the files I'm editing in emacs. Thus, when I try to save the files I've updated, tracerd tries to update its index, and thus takes the computing resources, lackness of which makes emacs to stop respond(In compiz fusion, emacs would just turn into gray and can't be operated).
I have not taken the time to view how this part of trackerd's code is written. and I've not tested trackerd and emacs on other versions of ubuntu or other distroes yet.
I think the possible reason is that trackerd is watching the files I'm editing in emacs. Thus, when I try to save the files I've updated, tracerd tries to update its index, and thus takes the computing resources, lackness of which makes emacs to stop respond(In compiz fusion, emacs would just turn into gray and can't be operated).
I have not taken the time to view how this part of trackerd's code is written. and I've not tested trackerd and emacs on other versions of ubuntu or other distroes yet.
2007-06-02
2006-12-13
It's really nice! Emacs 23在gnome下终于支持中文输入了。
After a cvs update this morning, I had a look at the changelog file src/Changelog.unicode and saw a new log:
2006-12-12 Kenichi Handa
* fontset.c (Finternal_char_font): Fix previous change.
In fact I've been always careing about changelogs about fonts except this time-_-. It's really a pity! I'll tell the reason later.
Then, I went to read papers. One or two hours later than that cvs update, I wanted to post something on the XWindow board at newsmth BBS. As a fanatical BBSer, I went to the Emacs board to see whether there would be something exciting(and I would go to LinuxApp and some other boards relevant with Linux and Free softwares). There! I saw that wonderful post which says that Emacs 23 finally supports Chinese inputing under gnome, even with the --enable-font-backend option.
So, I hurried to my terminal and compiled emacs again. Yes, that's it! I can input Chinese using fcitx now:-).
But, I'm not so sure what on earth are the changes that finally make Chinese inputing method work in Emacs 23 with --enable-font-backend.
PS: --enable-font-backend makes fonts much more pretty and smoother.
2006-12-12 Kenichi Handa
* fontset.c (Finternal_char_font): Fix previous change.
In fact I've been always careing about changelogs about fonts except this time-_-. It's really a pity! I'll tell the reason later.
Then, I went to read papers. One or two hours later than that cvs update, I wanted to post something on the XWindow board at newsmth BBS. As a fanatical BBSer, I went to the Emacs board to see whether there would be something exciting(and I would go to LinuxApp and some other boards relevant with Linux and Free softwares). There! I saw that wonderful post which says that Emacs 23 finally supports Chinese inputing under gnome, even with the --enable-font-backend option.
So, I hurried to my terminal and compiled emacs again. Yes, that's it! I can input Chinese using fcitx now:-).
But, I'm not so sure what on earth are the changes that finally make Chinese inputing method work in Emacs 23 with --enable-font-backend.
PS: --enable-font-backend makes fonts much more pretty and smoother.
订阅:
博文 (Atom)