help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some functions I hope are useful for others to


From: Pascal J. Bourguignon
Subject: Re: Some functions I hope are useful for others to
Date: Wed, 23 Dec 2009 20:16:03 +0100
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]