all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Some functions I hope are useful for others to
@ 2009-12-23 17:29 Cecil Westerhof
  2009-12-23 17:48 ` Richard Riley
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Cecil Westerhof @ 2009-12-23 17:29 UTC (permalink / raw)
  To: help-gnu-emacs

I wrote some functions to extend Emacs. I find them useful and share
them here in the hope they can be useful to others also. When things can
be done better: let me know.

The links:
    http://www.decebal.nl/EmacsLisp/sources/own-functions-buffer.el
    http://www.decebal.nl/EmacsLisp/sources/own-functions-general.el
    http://www.decebal.nl/EmacsLisp/sources/own-functions-time.el

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: Some functions I hope are useful for others to
  2009-12-23 17:29 Some functions I hope are useful for others to Cecil Westerhof
@ 2009-12-23 17:48 ` Richard Riley
       [not found] ` <mailman.84.1261590532.18930.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Richard Riley @ 2009-12-23 17:48 UTC (permalink / raw)
  To: help-gnu-emacs


Cecil Westerhof <Cecil@decebal.nl> writes:

> I wrote some functions to extend Emacs. I find them useful and share
> them here in the hope they can be useful to others also. When things can
> be done better: let me know.
>
> The links:
>     http://www.decebal.nl/EmacsLisp/sources/own-functions-buffer.el
>     http://www.decebal.nl/EmacsLisp/sources/own-functions-general.el
>     http://www.decebal.nl/EmacsLisp/sources/own-functions-time.el

A small festive suggestion:

If you feel they have a use for others then think about hosting them on
the emacs wiki and then they can be auto installed etc. (google up
auto-install etc) : http://www.emacswiki.org/emacs/AutoInstall

Your page would need to confirm to the standard sequence/link formats
that most people use and would be a lot more accessible to many and not
so susceptible to your own pages going down.

regards

r.







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

* Re: Some functions I hope are useful for others to
       [not found] ` <mailman.84.1261590532.18930.help-gnu-emacs@gnu.org>
@ 2009-12-23 18:19   ` Cecil Westerhof
  0 siblings, 0 replies; 7+ messages in thread
From: Cecil Westerhof @ 2009-12-23 18:19 UTC (permalink / raw)
  To: help-gnu-emacs

Richard Riley <rileyrgdev@gmail.com> writes:

>> I wrote some functions to extend Emacs. I find them useful and share
>> them here in the hope they can be useful to others also. When things can
>> be done better: let me know.
>>
>> The links:
>>     http://www.decebal.nl/EmacsLisp/sources/own-functions-buffer.el
>>     http://www.decebal.nl/EmacsLisp/sources/own-functions-general.el
>>     http://www.decebal.nl/EmacsLisp/sources/own-functions-time.el
>
> A small festive suggestion:
>
> If you feel they have a use for others then think about hosting them on
> the emacs wiki and then they can be auto installed etc. (google up
> auto-install etc) : http://www.emacswiki.org/emacs/AutoInstall

I'll look into it. But not immediately, I am a 'little' busy at the
moment.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: Some functions I hope are useful for others to
  2009-12-23 17:29 Some functions I hope are useful for others to Cecil Westerhof
  2009-12-23 17:48 ` Richard Riley
       [not found] ` <mailman.84.1261590532.18930.help-gnu-emacs@gnu.org>
@ 2009-12-23 19:16 ` Pascal J. Bourguignon
  2009-12-23 20:10   ` Cecil Westerhof
  2009-12-23 19:44 ` Cecil Westerhof
  3 siblings, 1 reply; 7+ messages in thread
From: Pascal J. Bourguignon @ 2009-12-23 19:16 UTC (permalink / raw)
  To: help-gnu-emacs

Cecil Westerhof <Cecil@decebal.nl> writes:

> I wrote some functions to extend Emacs. I find them useful and share
> them here in the hope they can be useful to others also. When things can
> be done better: let me know.
>
> The links:
>     http://www.decebal.nl/EmacsLisp/sources/own-functions-buffer.el

buffer-delete-lines --> kill-line
For example, to delete 3 lines, you type C-3 C-k (or C-u 3 C-k in a terminal).

buffer-to-unix --> universal-coding-system-argument
                   set-default-coding-systems
                   etc.

More precisely, when you load a file with DOS line termination, then
you get a (DOS) in the status line, and lines in the buffer (there's
no RET in the buffer!).  When you save a buffer (C-x C-s), it's saved
with the same line termination.  When you write out the buffer (C-x
C-w), the default-coding-systems are used, so if you specify a unix
coding system there, it will be saved as a unix text file.

If you want to force a coding system upon saving, you can use
universal-coding-system-argument.  For example, if you want to save a
buffer as iso-8859-1 with unix line terminations:

   C-x RET c iso-8859-1-unix RET   C-x C-s


>     http://www.decebal.nl/EmacsLisp/sources/own-functions-general.el

I find them quite specific.  (I wouldn't need these funtions).


>     http://www.decebal.nl/EmacsLisp/sources/own-functions-time.el

time-difference-formatted: do not do more than one thing in a
function.  Either compute a time difference, or format a time, but
don't do both!

Time formating is already provided by emacs format-time-string,
so your function is redundant.



Before an opening parenthesis, there can be only a quote, a space or
another opening parenthesis.

After a closing parenthesis, there can be only a closing parenthesis
or a space.

(Space can be either a SPC or a new line).

Notably, you need to put spaces between the funtion name and the
parameter list.




Finally, my own funtions are also my own-functions.   You should
rather use a unique prefix, such as:

nl.decebal.cecil-general.el
nl.decebal.cecil-buffer.el
nl.decebal.cecil-time.el

and you could also prefix your functions with the same to avoid
collision with my own functions:

nl.decebal.cecil.general/set-property-in-listo  
nl.decebal.cecil.time/emacs-uptime


For example, here is my emacs-uptime:


(defvar com.informatimago.time/*emacs-start-time*   (current-time)
   "For (emacs-uptime)")

(defun com.informatimago.time/emacs-uptime ()
  "Gives Emacs' uptime, based on global var `com.informatimago.time/*emacs-start-time*'."
  (interactive)
  (let* ((st com.informatimago.time/*emacs-start-time*)
         (cur (current-time))
         (hi-diff (- (car cur) (car st)))
         (tot-sec (+ (ash hi-diff 16) (- (cadr cur) (cadr st))))
         (days (/ tot-sec (* 60 60 24)))
         (hrs  (/ (- tot-sec (* days 60 60 24)) (* 60 60)))
         (mins (/ (- tot-sec (* days 60 60 24) (* hrs 60 60)) 60))
         (secs (/ (- tot-sec (* days 60 60 24) (* hrs 60 60) (* mins 60)) 1)))
    (message "Up %dd %dh %dm %ds (%s), %d buffers, %d files"
             days hrs mins secs
             (format-time-string "%a %Y-%m-%d %T" st)
             (length (buffer-list))
             (count t (buffer-list)
                    :test-not
                    (lambda (ignore buf)
                      (null (cdr (assoc 'buffer-file-truename
                                        (buffer-local-variables buf)))))))))

(defalias 'emacs-uptime 'com.informatimago.time/emacs-uptime)


Yours:   1 19:35:14
Mine:    Up 1d 19h 35m 21s (Tue 2009-12-22 00:31:09), 58 buffers, 11 files
Unix's:  20:08:56 up 1 day, 19:55,  3 users,  load average: 0.05, 0.08, 0.08


(Ok, I must admit that I don't apply that last advice for my
semi-published emacs code, but I sometimes use a pjb- prefix.  Too bad
emacs lisp has no packages).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay


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

* Re: Some functions I hope are useful for others to
  2009-12-23 17:29 Some functions I hope are useful for others to Cecil Westerhof
                   ` (2 preceding siblings ...)
  2009-12-23 19:16 ` Pascal J. Bourguignon
@ 2009-12-23 19:44 ` Cecil Westerhof
  3 siblings, 0 replies; 7+ messages in thread
From: Cecil Westerhof @ 2009-12-23 19:44 UTC (permalink / raw)
  To: help-gnu-emacs

Cecil Westerhof <Cecil@decebal.nl> writes:

> I wrote some functions to extend Emacs. I find them useful and share
> them here in the hope they can be useful to others also. When things can
> be done better: let me know.

I also made a little web-page. Makes things a little user friendly I
hope:
    http://www.decebal.nl/EmacsLisp/

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: Some functions I hope are useful for others to
  2009-12-23 19:16 ` Pascal J. Bourguignon
@ 2009-12-23 20:10   ` Cecil Westerhof
  2009-12-23 23:34     ` Pascal J. Bourguignon
  0 siblings, 1 reply; 7+ messages in thread
From: Cecil Westerhof @ 2009-12-23 20:10 UTC (permalink / raw)
  To: help-gnu-emacs

pjb@informatimago.com (Pascal J. Bourguignon) writes:

> buffer-delete-lines --> kill-line

Not complete. My buffer-delete-lines delete the complete line from the
beginning, kill-line does it from the cursor position.

> buffer-to-unix --> universal-coding-system-argument
>                    set-default-coding-systems
>                    etc.
>
> More precisely, when you load a file with DOS line termination, then
> you get a (DOS) in the status line, and lines in the buffer (there's
> no RET in the buffer!).  When you save a buffer (C-x C-s), it's saved
> with the same line termination.  When you write out the buffer (C-x
> C-w), the default-coding-systems are used, so if you specify a unix
> coding system there, it will be saved as a unix text file.

This works also when there are lines of all three types? And with my
function you get immediately rid of those ^M at the end of the line.


>>     http://www.decebal.nl/EmacsLisp/sources/own-functions-general.el
>
> I find them quite specific.  (I wouldn't need these funtions).

I find log-message very handy. You do not have to search for messages of
a certain process in *Messages*. (I use it for my gnus-idle-daemon.)
I find exit-depends-on-interactive also very handy. When calling a
function interactive it is nice to get a message in the mini buffer, but
not when a function is not called interactive.


>>     http://www.decebal.nl/EmacsLisp/sources/own-functions-time.el
>
> time-difference-formatted: do not do more than one thing in a
> function.  Either compute a time difference, or format a time, but
> don't do both!

I do. For computing the time difference I call time-difference in
time-difference-formatted.


> Time formating is already provided by emacs format-time-string,
> so your function is redundant.

I do not think so, because in my function the format is dependent on the
time difference.


> Before an opening parenthesis, there can be only a quote, a space or
> another opening parenthesis.

I started to do this. I am used that the parenthesis in which the
parameters are given are bound to the function name. In my newest code I
am using a space, but this code is a little older and should be changed
by me.

> Finally, my own funtions are also my own-functions.   You should
> rather use a unique prefix, such as:
>
> nl.decebal.cecil-general.el
> nl.decebal.cecil-buffer.el
> nl.decebal.cecil-time.el

That is a good idea.


> and you could also prefix your functions with the same to avoid
> collision with my own functions:
>
> nl.decebal.cecil.general/set-property-in-listo  
> nl.decebal.cecil.time/emacs-uptime

Used with defalias that is also a good idea.

But when I started writing those functions I did not think it would be
interesting for others. I hope I was wrong. :-D

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: Some functions I hope are useful for others to
  2009-12-23 20:10   ` Cecil Westerhof
@ 2009-12-23 23:34     ` Pascal J. Bourguignon
  0 siblings, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2009-12-23 23:34 UTC (permalink / raw)
  To: help-gnu-emacs

Cecil Westerhof <Cecil@decebal.nl> writes:

> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>
>> buffer-delete-lines --> kill-line
>
> Not complete. My buffer-delete-lines delete the complete line from the
> beginning, kill-line does it from the cursor position.
>
>> buffer-to-unix --> universal-coding-system-argument
>>                    set-default-coding-systems
>>                    etc.
>>
>> More precisely, when you load a file with DOS line termination, then
>> you get a (DOS) in the status line, and lines in the buffer (there's
>> no RET in the buffer!).  When you save a buffer (C-x C-s), it's saved
>> with the same line termination.  When you write out the buffer (C-x
>> C-w), the default-coding-systems are used, so if you specify a unix
>> coding system there, it will be saved as a unix text file.
>
> This works also when there are lines of all three types? And with my
> function you get immediately rid of those ^M at the end of the line.

What?  You have files with mixed newlines?  Eeerk!   ;-)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
You're always typing.
Well, let's see you ignore my
sitting on your hands.


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

end of thread, other threads:[~2009-12-23 23:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-23 17:29 Some functions I hope are useful for others to Cecil Westerhof
2009-12-23 17:48 ` Richard Riley
     [not found] ` <mailman.84.1261590532.18930.help-gnu-emacs@gnu.org>
2009-12-23 18:19   ` Cecil Westerhof
2009-12-23 19:16 ` Pascal J. Bourguignon
2009-12-23 20:10   ` Cecil Westerhof
2009-12-23 23:34     ` Pascal J. Bourguignon
2009-12-23 19:44 ` Cecil Westerhof

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.