From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Some functions I hope are useful for others to
Date: Wed, 23 Dec 2009 20:16:03 +0100 [thread overview]
Message-ID: <87ljgtqz64.fsf@hubble.informatimago.com> (raw)
In-Reply-To: 877hsdeh06.fsf@Traian.DecebalComp
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
next prev parent reply other threads:[~2009-12-23 19:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2009-12-23 20:10 ` Cecil Westerhof
2009-12-23 23:34 ` Pascal J. Bourguignon
2009-12-23 19:44 ` Cecil Westerhof
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ljgtqz64.fsf@hubble.informatimago.com \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).