unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* string func to use in .emacs
@ 2004-01-25  5:11 Peter Wu
  2004-01-25  6:31 ` Eli Zaretskii
       [not found] ` <mailman.1300.1075012227.928.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Wu @ 2004-01-25  5:11 UTC (permalink / raw)


I'm working on my .emacs file and would like to know if there is any
string func ready, such as string trimming, for use in .emacs. 

I know of the following link about string manipulation, which does not
offer more about trimming.

http://www.linuxselfhelp.com/gnu/elisp/html_chapter/elisp_5.html

-- 
       ,,,
      (o o)       Peter Wu
---ooO-(_)-Ooo--- Powered by GNU/Linux 2.4.22

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-25  5:11 string func to use in .emacs Peter Wu
@ 2004-01-25  6:31 ` Eli Zaretskii
       [not found] ` <mailman.1300.1075012227.928.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-01-25  6:31 UTC (permalink / raw)


> From: Peter Wu <peterwu@hotmail.com>
> Newsgroups: gnu.emacs.help
> Date: Sun, 25 Jan 2004 00:11:15 -0500
> 
> I'm working on my .emacs file and would like to know if there is any
> string func ready, such as string trimming, for use in .emacs. 

What is ``string trimming'', exactly?  What API do you have in mind?
It's hard to give you a good answer without knowing that much, since
string trimming has more than one possible meaning.

Likewise for the other string functions you need--please spell out the
details.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
       [not found] ` <mailman.1300.1075012227.928.help-gnu-emacs@gnu.org>
@ 2004-01-25 14:21   ` Peter Wu
  2004-01-25 17:45     ` Mario Domgörgen
  2004-01-25 17:59     ` Eli Zaretskii
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Wu @ 2004-01-25 14:21 UTC (permalink / raw)


On 25 Jan 2004 08:31:30 +0200, Eli Zaretskii wrote:

>> From: Peter Wu <peterwu@hotmail.com>
>> Newsgroups: gnu.emacs.help
>> Date: Sun, 25 Jan 2004 00:11:15 -0500
>> 
>> I'm working on my .emacs file and would like to know if there is any
>> string func ready, such as string trimming, for use in .emacs. 

> What is ``string trimming'', exactly?  What API do you have in mind?
> It's hard to give you a good answer without knowing that much, since
> string trimming has more than one possible meaning.

> Likewise for the other string functions you need--please spell out the
> details.

What I am looking for is like this:

input    := "Emacs "
output   := "Emacs"    

The trailing blank space is trimmed.

-- 
       ,,,
      (o o)       Peter Wu
---ooO-(_)-Ooo--- Powered by GNU/Linux 2.4.22

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-25 14:21   ` Peter Wu
@ 2004-01-25 17:45     ` Mario Domgörgen
  2004-01-26  0:26       ` Peter Wu
  2004-01-25 17:59     ` Eli Zaretskii
  1 sibling, 1 reply; 11+ messages in thread
From: Mario Domgörgen @ 2004-01-25 17:45 UTC (permalink / raw)


Peter Wu <peterwu@hotmail.com> writes:

> What I am looking for is like this:
>
> input    := "Emacs "
> output   := "Emacs"    
>
> The trailing blank space is trimmed.

,----[ C-h f delete-trailing-whitespace RET ]
| delete-trailing-whitespace is an interactive compiled Lisp function in
| `simple'.  (delete-trailing-whitespace)
| 
| Delete all the trailing whitespace across the current buffer.  All
| whitespace after the last non-whitespace character in a line is
| deleted.  This respects narrowing, created by C-x n n and friends.  A
| formfeed is not considered whitespace by this function.
| 
| [back]
`----

Look at this function to start with....

Mario

-- 
The Web site you seek
cannot be located but
endless others exist

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-25 14:21   ` Peter Wu
  2004-01-25 17:45     ` Mario Domgörgen
@ 2004-01-25 17:59     ` Eli Zaretskii
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-01-25 17:59 UTC (permalink / raw)


> From: Peter Wu <peterwu@hotmail.com>
> Newsgroups: gnu.emacs.help
> Date: Sun, 25 Jan 2004 09:21:07 -0500
> 
> What I am looking for is like this:
> 
> input    := "Emacs "
> output   := "Emacs"    
> 
> The trailing blank space is trimmed.

Try this:

  (let ((i (string-match " +\\'" input)))
    (when i
         (setq output (substring input 0 i))))

(You may wish to replace `output' with `input', so that it is
destructively trimmed.)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-25 17:45     ` Mario Domgörgen
@ 2004-01-26  0:26       ` Peter Wu
  2004-01-26  0:44         ` Jesper Harder
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Wu @ 2004-01-26  0:26 UTC (permalink / raw)


On Sun, 25 Jan 2004 18:45:05 +0100, Mario Domgörgen wrote:

> Peter Wu <peterwu@hotmail.com> writes:
>> What I am looking for is like this:
>> 
>> input    := "Emacs "
>> output   := "Emacs"    
>> 
>> The trailing blank space is trimmed.

> ,----[ C-h f delete-trailing-whitespace RET ]
> | delete-trailing-whitespace is an interactive compiled Lisp function in
> | `simple'.  (delete-trailing-whitespace)
> | 
> | Delete all the trailing whitespace across the current buffer.  All
> | whitespace after the last non-whitespace character in a line is
> | deleted.  This respects narrowing, created by C-x n n and friends.  A
> | formfeed is not considered whitespace by this function.
> | 
> | [back]
> `----

> Look at this function to start with....

This function seems to trim the trailing whitespaces in a buffer. How can
I use it to trim a string variable?

-- 
       ,,,
      (o o)       Peter Wu
---ooO-(_)-Ooo--- Powered by GNU/Linux 2.4.22

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-26  0:26       ` Peter Wu
@ 2004-01-26  0:44         ` Jesper Harder
  2004-01-26  3:16           ` Peter Wu
  0 siblings, 1 reply; 11+ messages in thread
From: Jesper Harder @ 2004-01-26  0:44 UTC (permalink / raw)


Peter Wu <peterwu@hotmail.com> writes:

> On Sun, 25 Jan 2004 18:45:05 +0100, Mario Domgörgen wrote:
>
>> ,----[ C-h f delete-trailing-whitespace RET ]
>
>> Look at this function to start with....
>
> This function seems to trim the trailing whitespaces in a
> buffer. How can I use it to trim a string variable?

A common idiom when you have a function that works in a buffer and
want to apply it to a string is to use a temporary buffer:

(defun string-trim-right (str)
  (with-temp-buffer
    (insert str)
    (delete-trailing-whitespace)
    (buffer-string)))

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-26  0:44         ` Jesper Harder
@ 2004-01-26  3:16           ` Peter Wu
  2004-01-26  3:57             ` Jesper Harder
  2004-01-26  7:03             ` Eli Zaretskii
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Wu @ 2004-01-26  3:16 UTC (permalink / raw)


On Mon, 26 Jan 2004 01:44:45 +0100, Jesper Harder wrote:

> Peter Wu <peterwu@hotmail.com> writes:
>> On Sun, 25 Jan 2004 18:45:05 +0100, Mario Domgörgen wrote:
>> 
>>> ,----[ C-h f delete-trailing-whitespace RET ]
>> 
>>> Look at this function to start with....
>> 
>> This function seems to trim the trailing whitespaces in a
>> buffer. How can I use it to trim a string variable?

> A common idiom when you have a function that works in a buffer and
> want to apply it to a string is to use a temporary buffer:

> (defun string-trim-right (str)
>   (with-temp-buffer
>     (insert str)
>     (delete-trailing-whitespace)
>     (buffer-string)))

I tried to use the func and got an error:

  Symbol's value as variable is void: string-trim-right

My code:

(string-trim-right("Emacs "))
=> "Emacs" (the expected output)

-- 
       ,,,
      (o o)       Peter Wu
---ooO-(_)-Ooo--- Powered by GNU/Linux 2.4.22

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-26  3:16           ` Peter Wu
@ 2004-01-26  3:57             ` Jesper Harder
  2004-01-26 14:55               ` Peter Wu
  2004-01-26  7:03             ` Eli Zaretskii
  1 sibling, 1 reply; 11+ messages in thread
From: Jesper Harder @ 2004-01-26  3:57 UTC (permalink / raw)


Peter Wu <peterwu@hotmail.com> writes:

> On Mon, 26 Jan 2004 01:44:45 +0100, Jesper Harder wrote:
>
>> A common idiom when you have a function that works in a buffer and
>> want to apply it to a string is to use a temporary buffer:
>
>> (defun string-trim-right (str)
>>   (with-temp-buffer
>>     (insert str)
>>     (delete-trailing-whitespace)
>>     (buffer-string)))
>
> I tried to use the func and got an error: My code:
>
> (string-trim-right("Emacs "))

That should be:

   (string-trim-right "Emacs ")

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-26  3:16           ` Peter Wu
  2004-01-26  3:57             ` Jesper Harder
@ 2004-01-26  7:03             ` Eli Zaretskii
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-01-26  7:03 UTC (permalink / raw)


> From: Peter Wu <peterwu@hotmail.com>
> Newsgroups: gnu.emacs.help
> Date: Sun, 25 Jan 2004 22:16:02 -0500
> 
> > (defun string-trim-right (str)
> >   (with-temp-buffer
> >     (insert str)
> >     (delete-trailing-whitespace)
> >     (buffer-string)))
> 
> I tried to use the func and got an error:
> 
>   Symbol's value as variable is void: string-trim-right
> 
> My code:
> 
> (string-trim-right("Emacs "))
> => "Emacs" (the expected output)

You need to evaluate the function's definition, otherwise how will
Emacs know what is string-trim-right?  To do that, put the cursor
after the right closing paren of the function, and type "C-x C-e".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: string func to use in .emacs
  2004-01-26  3:57             ` Jesper Harder
@ 2004-01-26 14:55               ` Peter Wu
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Wu @ 2004-01-26 14:55 UTC (permalink / raw)


On Mon, 26 Jan 2004 04:57:37 +0100, Jesper Harder wrote:

> Peter Wu <peterwu@hotmail.com> writes:
>> On Mon, 26 Jan 2004 01:44:45 +0100, Jesper Harder wrote:
>> 
>>> A common idiom when you have a function that works in a buffer and
>>> want to apply it to a string is to use a temporary buffer:
>> 
>>> (defun string-trim-right (str)
>>> (with-temp-buffer
>>> (insert str)
>>> (delete-trailing-whitespace)
>>> (buffer-string)))
>> 
>> I tried to use the func and got an error: My code:
>> 
>> (string-trim-right("Emacs "))

> That should be:

>    (string-trim-right "Emacs ")

This takes care of the problem. Thanks!

-- 
       ,,,
      (o o)       Peter Wu
---ooO-(_)-Ooo--- Powered by GNU/Linux 2.4.22

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-01-26 14:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-25  5:11 string func to use in .emacs Peter Wu
2004-01-25  6:31 ` Eli Zaretskii
     [not found] ` <mailman.1300.1075012227.928.help-gnu-emacs@gnu.org>
2004-01-25 14:21   ` Peter Wu
2004-01-25 17:45     ` Mario Domgörgen
2004-01-26  0:26       ` Peter Wu
2004-01-26  0:44         ` Jesper Harder
2004-01-26  3:16           ` Peter Wu
2004-01-26  3:57             ` Jesper Harder
2004-01-26 14:55               ` Peter Wu
2004-01-26  7:03             ` Eli Zaretskii
2004-01-25 17:59     ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).