From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Some functions I hope are useful for others to Date: Wed, 23 Dec 2009 20:16:03 +0100 Organization: Informatimago Message-ID: <87ljgtqz64.fsf@hubble.informatimago.com> References: <877hsdeh06.fsf@Traian.DecebalComp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1261597261 30963 80.91.229.12 (23 Dec 2009 19:41:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Dec 2009 19:41:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 23 20:40:54 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 1NNX4n-0002D4-Lk for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Dec 2009 20:40:53 +0100 Original-Received: from localhost ([127.0.0.1]:58406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NNX4n-0004M5-MH for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Dec 2009 14:40:53 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 119 Original-X-Trace: individual.net 8+V1HwMU6jP8s+jUwYxf/gsZsibN3eL+ElCUlQdYXsjdczKsyn Cancel-Lock: sha1:NWE0NWVkOThhNDY3MTk0ZjdhMzdiMzJkNzIwOGYwNjJmNDYwM2RlZQ== sha1:iuChqQUMhHFPPfQvHTNG7VfAw2U= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:175751 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:70827 Archived-At: Cecil Westerhof 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