unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* general-purpose.el - a general-forms-resource-utility
@ 2006-07-06 10:11 Andreas Roehler
  2006-07-06 19:57 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Andreas Roehler @ 2006-07-06 10:11 UTC (permalink / raw)



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 <kifer@cs.sunysb.edu> ;;

;;;_. *** 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 <wmperry@cs.indiana.edu" ;;

;;;_. *** decimal-to-alpha

(defun w3-decimal-to-alpha (n)
  "Convert from decimal to alphabetical (a, b, c, ..., aa, ab,...)"
  (cond
   ((< n 1) (char-to-string ?Z))
   ((<= n 26) (char-to-string (+ ?A (1- n))))
   (t (concat (w3-decimal-to-alpha (/ n 26))
          (w3-decimal-to-alpha (% n 26))))))

;;   Source: w3-display.el --- W3 display engine.   Author: William M. 
Perry <wmperry@cs.indiana.edu" ;;

;;;_. * clipboard related functions
;;;_. ** clipboard and x-select-enable-clipboard

(defun clipboard-yank ()
  "Insert the clipboard contents, or the last stretch of killed text."
  (interactive)
  (let ((x-select-enable-clipboard t))
    (yank)))

(defun clipboard-kill-ring-save (beg end)
  "Copy region to kill ring, and save in the X clipboard."
  (interactive "r")
  (let ((x-select-enable-clipboard t))
    (kill-ring-save beg end)))

(defun clipboard-kill-region (beg end)
  "Kill the region, and save it in the X clipboard."
  (interactive "r")
  (let ((x-select-enable-clipboard t))
    (kill-region beg end)))

;; Source: menu-bar.el ;;

;;;;; End

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-06 10:11 general-purpose.el - a general-forms-resource-utility Andreas Roehler
@ 2006-07-06 19:57 ` Eli Zaretskii
  2006-07-06 20:34   ` Lennart Borgman
  2006-07-07  6:13   ` Andreas Roehler
  2006-07-07  4:14 ` Richard Stallman
  2006-07-07  4:15 ` Richard Stallman
  2 siblings, 2 replies; 12+ messages in thread
From: Eli Zaretskii @ 2006-07-06 19:57 UTC (permalink / raw)
  Cc: emacs-devel

> Date: Thu, 06 Jul 2006 12:11:01 +0200
> From: Andreas Roehler <andreas.roehler@easy-emacs.de>
> 
> 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.

Why do we need a new file for these?  We already have subr.el, why not
add things to it?

> To have an (indexed) collection of all these goodies,
> not only developers would gain an additional - sorted -
> resource

I agree, but this just boils down to additions to the ELisp manual, or
(if the current size is already too much for print) for an additional
manual, perhaps included in the on-line version with the @ifnottex
conditionals we use in the user manual.

> 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)

An Info manual already supports a similar facility, so we could just
use it.

> - 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

Is there something beyond completion here?

> - display related topics as customize does with
>   parent groups

There's a C-h subcommand to do that.

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-06 19:57 ` Eli Zaretskii
@ 2006-07-06 20:34   ` Lennart Borgman
  2006-07-07  6:13   ` Andreas Roehler
  1 sibling, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2006-07-06 20:34 UTC (permalink / raw)
  Cc: Andreas Roehler, emacs-devel

Eli Zaretskii wrote:
>> - 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
>>     
>
> Is there something beyond completion here?
>   
I do not know what OP actually meant, but I think it would be useful to 
easily have access to general functions you may need somewhere. 
Completion would be very fine in my opinion.

>   
>> - display related topics as customize does with
>>   parent groups
>>     
>
> There's a C-h subcommand to do that.
>
>   
I must have missed something. Is there an hiearchy for functions?

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-06 10:11 general-purpose.el - a general-forms-resource-utility Andreas Roehler
  2006-07-06 19:57 ` Eli Zaretskii
@ 2006-07-07  4:14 ` Richard Stallman
  2006-07-07  6:32   ` Andreas Roehler
  2006-07-07  4:15 ` Richard Stallman
  2 siblings, 1 reply; 12+ messages in thread
From: Richard Stallman @ 2006-07-07  4:14 UTC (permalink / raw)
  Cc: emacs-devel

    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.

These are not useful.  There are other good ways to do these things.

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-06 10:11 general-purpose.el - a general-forms-resource-utility Andreas Roehler
  2006-07-06 19:57 ` Eli Zaretskii
  2006-07-07  4:14 ` Richard Stallman
@ 2006-07-07  4:15 ` Richard Stallman
  2006-07-07  7:08   ` Andreas Roehler
  2 siblings, 1 reply; 12+ messages in thread
From: Richard Stallman @ 2006-07-07  4:15 UTC (permalink / raw)
  Cc: emacs-devel

Some of these functions might be useful.
For instance, concat-and-truncate-string-left might be
useful to add (but not until after the release).

Some, such as nonempty-string-p, are clearly so simple
that there's no point in defining them.

Most of the rest just don't see very widely useful.
But if we find that they are widely useful, we could add them.

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-06 19:57 ` Eli Zaretskii
  2006-07-06 20:34   ` Lennart Borgman
@ 2006-07-07  6:13   ` Andreas Roehler
  1 sibling, 0 replies; 12+ messages in thread
From: Andreas Roehler @ 2006-07-07  6:13 UTC (permalink / raw)
  Cc: emacs-devel

Eli Zaretskii schrieb:
>> Date: Thu, 06 Jul 2006 12:11:01 +0200
>> From: Andreas Roehler <andreas.roehler@easy-emacs.de>
>>
>> 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.
>>     
>
> Why do we need a new file for these?  We already have subr.el, why not
> add things to it?
>
>   

Thanks. 

See several questions around: To copy it into a new file would
produce volume. Altogether as the definitions
are already there. From this point of view it's better
to copy them from the original location into a
temporary buffer just the moment, the user wants to see
it.

Given this, another question results: What, if the
source changed and the indicated form isn't longer in
place? Maintain a fall-back file somewhere in the net?
Error message?

Subr.el isn't suitable in any case as `general-purpose'
is conceived as a user facility. The collection should not
be evaluated per default, it should
not change the sources by themselves.

Certainly as a result there might be cases--and
probably a lot of them--where it's obvious the
definition should go into subr.el - as string-strip
originating from newcomment-string-strip. But that will
be another process.

 
__
Andreas Roehler

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-07  4:14 ` Richard Stallman
@ 2006-07-07  6:32   ` Andreas Roehler
  2006-07-07  7:55     ` Thien-Thi Nguyen
  2006-07-08  1:12     ` Richard Stallman
  0 siblings, 2 replies; 12+ messages in thread
From: Andreas Roehler @ 2006-07-07  6:32 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman schrieb:
>     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.
>
> These are not useful.  There are other good ways to do these things.
>   
OK. But which? Where and how to find it quickly?

What I tried to say is: The sources are full of
paralell defined subroutines - more or less useful and
suitable.

There are at least six different scattered string-strip
definitions I esteem.

Why not think about a way to relate and reflect these
different - already exiting and delivered -
definitions?

__
Andreas Roehler

PS. Probably the message's subject should not say `a
general-forms-resource-utility', rather `towards a
general-forms-resource-utility' - that's to late
now. :)

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-07  4:15 ` Richard Stallman
@ 2006-07-07  7:08   ` Andreas Roehler
  0 siblings, 0 replies; 12+ messages in thread
From: Andreas Roehler @ 2006-07-07  7:08 UTC (permalink / raw)


Richard Stallman schrieb:
> Some of these functions might be useful.
>   
Thanks. However, I'm afraid you are missing the point
of the intended facility somehow.

The collection should not change the sources by
themselves.

A discussion of general parts of the sources might
be--and probably will be--one of the fruitful results.

Gave the examples solely to prove they exist, to
describe what the terminus `general-purpose-function'
should mean.

The question at stake is how to do the collecting
easily, how to make the results available. Where to
dock on?

Is there a classification/grouping to rely on?
Info-nodes?  Custom-groups?

__
Andreas Roehler

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-07  6:32   ` Andreas Roehler
@ 2006-07-07  7:55     ` Thien-Thi Nguyen
  2006-07-07  8:50       ` Andreas Roehler
  2006-07-08  1:12     ` Richard Stallman
  1 sibling, 1 reply; 12+ messages in thread
From: Thien-Thi Nguyen @ 2006-07-07  7:55 UTC (permalink / raw)
  Cc: emacs-devel

Andreas Roehler <andreas.roehler@easy-emacs.de> writes:

> Why not think about a way to relate and reflect these different
> - already exiting and delivered - definitions?

probably this has already been thought about.  see, for example:

http://www.norvig.com/paip/unify.lisp
http://www.norvig.com/paip/README.html

a related idea is to unify byte-code -- that would be cool.

thi

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-07  7:55     ` Thien-Thi Nguyen
@ 2006-07-07  8:50       ` Andreas Roehler
  2006-07-07 16:04         ` Thien-Thi Nguyen
  0 siblings, 1 reply; 12+ messages in thread
From: Andreas Roehler @ 2006-07-07  8:50 UTC (permalink / raw)
  Cc: Richard Stallman, emacs-devel

Thien-Thi Nguyen schrieb:
> Andreas Roehler <andreas.roehler@easy-emacs.de> writes:
>
>   
>> Why not think about a way to relate and reflect these different
>> - already exiting and delivered - definitions?
>>     
>
> probably this has already been thought about.  see, for example:
>
> http://www.norvig.com/paip/unify.lisp
> http://www.norvig.com/paip/README.html
>
> a related idea is to unify byte-code -- that would be cool.
>
> thi
>   

Thanks a lot! That's real interesting stuff there.

Let me say nonetheless that `unification' might be a
result--and certainly will be in some cases--but not
the primary goal of the project - that's wider, a more
general one.

If we agree that scattered general-purpose-functions
exist, one of the interesting questions is: Why?

What is the situation of the developer while writing
the fourth or fifth string-strip function?

Might be that

- none of the existing are suitable

- he ignores the other one.

Both seems possible, also in combination.

As big as the sources are I doubt that someone will
claim to know everything.

Also the question of suitability is no easy one -
following the discussion around string-strip these days
I don't see a way of automatized unification.

In any case it would help a lot if we could - while
writing - give some keyword, for example `correct user
input' and get a list of possible forms.

(That's the case already with `apropos' somehow, that's
not a new idea as such, so I will also examine
`apropos' in this context.)


__
Andreas Roehler

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-07  8:50       ` Andreas Roehler
@ 2006-07-07 16:04         ` Thien-Thi Nguyen
  0 siblings, 0 replies; 12+ messages in thread
From: Thien-Thi Nguyen @ 2006-07-07 16:04 UTC (permalink / raw)
  Cc: emacs-devel

Andreas Roehler <andreas.roehler@easy-emacs.de> writes:

> If we agree that scattered general-purpose-functions
> exist, one of the interesting questions is: Why?

writing code can be fun for its own sake.  often people take this joy
and it fills them enough so that other joys become uninteresting to
pursue.  emacs can accomodate these redundancies and slowly over time
unify them as their frequency passes the threshold of someone else's
joy-driven needs, and thus is a live example of pluralistic freedom.

personally, i think re-organizing things as mostly uninteresting.
however, a program that would do the re-organizing i'd read w/ pleasure.

thi

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

* Re: general-purpose.el - a general-forms-resource-utility
  2006-07-07  6:32   ` Andreas Roehler
  2006-07-07  7:55     ` Thien-Thi Nguyen
@ 2006-07-08  1:12     ` Richard Stallman
  1 sibling, 0 replies; 12+ messages in thread
From: Richard Stallman @ 2006-07-08  1:12 UTC (permalink / raw)
  Cc: emacs-devel

    What I tried to say is: The sources are full of
    paralell defined subroutines - more or less useful and
    suitable.

Only a few of them are really worth doing anything about.

Those that are worth while, we can move into subr.el
and document -- after the release!  For now, let's not spend
time on them.  We need to fix the bugs and do the items
in FOR-RELEASE.

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

end of thread, other threads:[~2006-07-08  1:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-06 10:11 general-purpose.el - a general-forms-resource-utility Andreas Roehler
2006-07-06 19:57 ` Eli Zaretskii
2006-07-06 20:34   ` Lennart Borgman
2006-07-07  6:13   ` Andreas Roehler
2006-07-07  4:14 ` Richard Stallman
2006-07-07  6:32   ` Andreas Roehler
2006-07-07  7:55     ` Thien-Thi Nguyen
2006-07-07  8:50       ` Andreas Roehler
2006-07-07 16:04         ` Thien-Thi Nguyen
2006-07-08  1:12     ` Richard Stallman
2006-07-07  4:15 ` Richard Stallman
2006-07-07  7:08   ` Andreas Roehler

Code repositories for project(s) associated with this public inbox

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

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).