From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Roehler Newsgroups: gmane.emacs.devel Subject: general-purpose.el - a general-forms-resource-utility Date: Thu, 06 Jul 2006 12:11:01 +0200 Message-ID: <44ACE1B5.10909@easy-emacs.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1152180601 20501 80.91.229.2 (6 Jul 2006 10:10:01 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 6 Jul 2006 10:10:01 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 06 12:09:56 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FyQnu-0000Fe-UX for ged-emacs-devel@m.gmane.org; Thu, 06 Jul 2006 12:09:51 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FyQnu-00019h-0v for ged-emacs-devel@m.gmane.org; Thu, 06 Jul 2006 06:09:50 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FyQng-00018v-Bb for emacs-devel@gnu.org; Thu, 06 Jul 2006 06:09:36 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FyQnc-000185-Cs for emacs-devel@gnu.org; Thu, 06 Jul 2006 06:09:36 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FyQnc-000181-7w for emacs-devel@gnu.org; Thu, 06 Jul 2006 06:09:32 -0400 Original-Received: from [212.227.126.187] (helo=moutng.kundenserver.de) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FyQnm-0001oZ-6d for emacs-devel@gnu.org; Thu, 06 Jul 2006 06:09:42 -0400 Original-Received: from [84.190.201.244] (helo=[192.168.178.23]) by mrelayeu.kundenserver.de (node=mrelayeu2) with ESMTP (Nemesis), id 0MKwtQ-1FyQna1pnN-0001JD; Thu, 06 Jul 2006 12:09:31 +0200 User-Agent: Thunderbird 1.5.0.4 (X11/20060516) Original-To: emacs-devel X-Provags-ID: kundenserver.de abuse@kundenserver.de login:62d13292e0fce6aaed56aaadcb96352d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:56622 Archived-At: There are general usable functions scattered in the source files, which are useful in a lot of circumstances and could be callable in a given context. Roman-to-latin- and Latin-to-roman-numbers for example. Just today I saw (defun region-around-match (&optional n) (set-mark (match-beginning n)) (goto-char (match-end n))) (defun region-to-string () (buffer-substring (min (point) (mark)) (max (point) (mark)))) in mlsupport.el. To have an (indexed) collection of all these goodies, not only developers would gain an additional - sorted - resource: This would also be useful for beginners to learn Elisp - as function given there will be rather basic ones, avoiding complexity. Also the Elisp-Manual could refer to in order to give more examples, to deepen understanding. To show up such basic utilities one by one and in relation might help finding errors and/or to optimize usage. Already started to collect some forms (example below) but realize, this should not be done by hand. Post this here, as there are probably more ideas to consider before a major writing effort starts. At the moment I see the following requirements at such a general-resource-utility: - take a given function or form where the point is in and prompt the user where to sort it (as groups in customize deliver a hierarchy and system) - display a list of clickable functions or forms the way `apropos' does; i.e. M-x `general-resource-utility' RET `string-strip' should display several string-strip-utilities to examine, insert at point etc. - allow users to edit the collection via copy-and-paste; provide some automated indexing afterward - display related topics as customize does with parent groups - collect resources from inside Emacs and third party stuff separately. (As a lot of users and me too use such stuff, it should not be impossible to collect and use it, provided it doesn't not disturb distribution. There might be - and should be probably - a warning at least once in that case.) --- Thought to use/adapt cus-edit.el as a starting point. Please send your suggestions and/or objections. __ Andreas Roehler ;;; ;; Please look with patience at this decent beginning :) ;;;_. * move related functions (defun skip-blank-lines-backward () " " (interactive) (while (looking-at "[ \t]*$") (forward-line -1)) (forward-line 1)) (defun skip-blank-lines-forward () " " (interactive) (while (looking-at "[ \t\n]") (forward-line 1)) (forward-line -1)) ;;;_. * string related functions ;;;_. ** strip-whitespace ;;;_. *** string-strip (defun string-strip (str beforep afterp) "Strip STR of any leading (if BEFOREP) and/or trailing (if AFTERP) space. " (string-match (concat "\\`" (if beforep "\\s-*") "\\(.*?\\)" (if afterp "\\s-*\n?") "\\'") str) (match-string 1 str)) ;; Source: comment-string-strip, newcomment.el, GNU Emacs 22.0.50.1 ;; ;;;_. *** truncate-string-left (defun concat-and-truncate-string-left (str prefix newlen) ;; leave space for ... on the left (let ((len (length str)) (lenprefix (length prefix)) substr) (if (<= len newlen) str (setq newlen (max 0 (- newlen lenprefix))) (setq substr (substring str (max 0 (- len 1 newlen)))) (concat prefix substr)))) ;; Example: ;; (concat-and-truncate-string-left "dasddddd" "+++" 4) ;; -> "+++dd" ;; following ediff-truncate-string-left from ediff-init.el ;;;_. *** nonempty-string-p (defsubst nonempty-string-p (string) (and (stringp string) (not (string= string "")))) ;; Source: ediff-nonempty-string-p; ediff-init.el --- ;; Macros, variables, and defsubsts used by Ediff ;; Author: Michael Kifer ;; ;;;_. *** kill-trailing-spaces ;;;_. *** clean-out-spaces (defun string-reverse (s) "Return the mirror image of string S, without any trailing space." (comment-string-strip (concat (nreverse (string-to-list s))) nil t)) ;; Source: comment-string-reverse, newcomment.el, GNU Emacs 22.0.50.1 ;; ;;;_. ** numeral-string-conversions ;;;_. *** decimal-to-roman (defvar w3-roman-characters "ivxLCDMVX" "Roman numerals.") (defun w3-decimal-to-roman (n) "Convert from decimal to roman numerals" (let ((curmod 1000) (str "") (j 7) i2 k curcnt) (while (>= curmod 1) (if (>= n curmod) (progn (setq curcnt (/ n curmod) n (- n (* curcnt curmod))) (if (= 4 (% curcnt 5)) (setq i2 (+ j (if (> curcnt 5) 1 0)) str (format "%s%c%c" str (aref w3-roman-characters (1- j)) (aref w3-roman-characters i2))) (progn (if (>= curcnt 5) (setq str (format "%s%c" str (aref w3-roman-characters j)) curcnt (- curcnt 5))) (setq k 0) (while (< k curcnt) (setq str (format "%s%c" str (aref w3-roman-characters (1- j))) k (1+ k))))))) (setq curmod (/ curmod 10) j (- j 2))) str)) ;; Source: w3-display.el --- W3 display engine. Author: William M. Perry