From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wang Lei Newsgroups: gmane.emacs.help Subject: Re: Why emacsclient -e "(current-word nil t)" does not print ? Date: Wed, 22 Jul 2009 21:27:01 +0800 Message-ID: References: <87r5waa3t8.fsf@galatea.local> <7cskgqjm0s.fsf@pbourguignon.informatimago.com> <7ck522jh0n.fsf@pbourguignon.informatimago.com> <7cy6qihxdo.fsf@pbourguignon.anevia.com> <87bpnd9qdz.wl%anselm.helbig+news2009@googlemail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1248269422 20757 80.91.229.12 (22 Jul 2009 13:30:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Jul 2009 13:30:22 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: anselm.helbig+news2009@googlemail.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 22 15:30:15 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MTbtd-0005Xn-S3 for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Jul 2009 15:30:14 +0200 Original-Received: from localhost ([127.0.0.1]:40022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTbtd-00016X-0U for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Jul 2009 09:30:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTbqZ-0008AA-Qt for help-gnu-emacs@gnu.org; Wed, 22 Jul 2009 09:27:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTbqZ-00089a-Aw for help-gnu-emacs@gnu.org; Wed, 22 Jul 2009 09:27:03 -0400 Original-Received: from [199.232.76.173] (port=33379 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTbqY-00089M-Vw for help-gnu-emacs@gnu.org; Wed, 22 Jul 2009 09:27:03 -0400 Original-Received: from qw-out-1920.google.com ([74.125.92.144]:21224) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MTbqY-0000DH-Gq for help-gnu-emacs@gnu.org; Wed, 22 Jul 2009 09:27:02 -0400 Original-Received: by qw-out-1920.google.com with SMTP id 5so87088qwf.24 for ; Wed, 22 Jul 2009 06:27:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=GPFw9bKRauyZ8lNYaQl4sc/wcFN/aP3vjWsW6NjoJjY=; b=BRiNXm0sbckAxYX6HLI8RskCPfgD60Hjd868E7r4462u9sB0tqKqB1b8LTfgHk0zFu wup/0R1jtDnBNzUgBuKnoHKhYpEKiJe3rtuZBcC5ndQKGRvUxJm5jwGFfmSWrb/649wQ o2y5qrcUvrirFamywiBPeGXv7yNALlEuuBX0g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=PgB0mwIdy0S9gSsiOnf6xUZFWHyzRUJdG4HcdlU9+SBKdtBTh9DHiBImrjfYSo4TZQ KsCdATCc766bP8Jeg+X4OIUoRIKNM99mKjEXjAX9mE7HD3uWYjYvrswhe45bGyRiXoi+ FLfTq/exE6ciqCaAlcOhzADSjibTruZrCHVUU= Original-Received: by 10.220.95.149 with SMTP id d21mr401277vcn.104.1248269221570; Wed, 22 Jul 2009 06:27:01 -0700 (PDT) In-Reply-To: <87bpnd9qdz.wl%anselm.helbig+news2009@googlemail.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:66337 Archived-At: Thanks! It works. I have finished it. Here is the code. -------------------->8-------------------->8-------------------- (defvar sdcv-replace-template ",$|^`|\\.$|^'|'$|\\?$") (defvar emacs-window-name "@EMACS@") (defun display-message-seconds (message seconds #!optional attributes) "Display message for N seconds." (interactive) (display-message message attributes) (make-timer (lambda () (display-message)) seconds)) (defun sdcv-get-word () "Get the word from current-word in emacs or selection or user input." (let* ((stream (make-string-output-stream)) (process (make-process stream)) (title "Enter String ") (word "") (result "")) (if (string= (window-name (input-focus)) emacs-window-name) (progn (call-process process nil "emacsclient" "-e" "(with-current-buffer (window-buffer (frame-first-window)) (current-word nil t))") (setq word (get-output-stream-string stream)) (setq word (string-replace "^\"(.+)\"\n" "\\1" word))) (setq word (string-replace sdcv-replace-template "" (x-get-selection 'PRIMARY)))) (setq word (string-replace sdcv-replace-template "" word)) (setq title (concat title "(" word "):" )) (setq result (prompt-for-string title)) (if (string= result "") word result))) (defun sdcv-search () "Search word with sdcv." (interactive) (let* ((word (sdcv-get-word)) (output (make-string-output-stream)) (proc (make-process output)) (errmsg "NO definite result. Try again.") (msg-attr '((position . (0 . 0)) (background . "LightGoldenrod1") (foreground . "black")))) (call-process proc nil "sdcv" "-n" "--data-dir" "~/.stardict/dic/stardict-langdao-ec-gb-2.4.2/" word) (setq output (get-output-stream-string output)) (if (> (when (string-match "Found \(..?\) items" output) (string->number (expand-last-match "\\1"))) 1) (display-message-seconds errmsg 2 msg-attr) (display-message-seconds output 5 msg-attr)))) -------------------->8-------------------->8-------------------- This is librep, it's like elisp, used in sawfish wm. Maybe it's useless for you at all. Just have a look. ;) On 7/22/09, Anselm Helbig wrote: >> NOW. Maybe having two choices is ok. Because if I really want to >> integrate everything, "get word from screen" should be my choice, not >> selection ang prompt. Thanks for you help! > > So I understand that you really require to call your code from outside > of emacs. When you're not in emacs, there's AFAIK no way to tell which > buffer is "current". You may have many buffers, and also any number of > frames and windows. This code takes the buffer that the first window > of the currently selected frame is pointing to, which will probably do > what you want: > > (with-current-buffer (window-buffer (frame-first-window)) (current-word > nil t)) > > HTH, > > Anselm > > > -- > Anselm Helbig > mailto:anselm.helbig+news2009@googlemail.com > -- Regards Lei