all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Przemysław Wojnowski" <esperanto@cumego.com>
To: Artur Malabarba <bruce.connor.am@gmail.com>
Cc: Emacs Developers <emacs-devel@gnu.org>
Subject: Re: Separating obarray handling from abbrevs
Date: Sun, 01 Nov 2015 23:17:55 +0100	[thread overview]
Message-ID: <87r3k95ppo.fsf@cumego.com> (raw)
In-Reply-To: <CAAdUY-LJwn+6yqCMw_O_3DxcOQKyRoLbRZP3HzuUNqB6JDNGTA@mail.gmail.com> (Artur Malabarba's message of "Sun, 1 Nov 2015 13:11:24 +0000")

Artur Malabarba <bruce.connor.am@gmail.com> writes:
> 2015-10-31 13:21 GMT+00:00 Przemysław Wojnowski <esperanto@cumego.com>:
>> Can I move obarrays functionality from abbrev.el to a separate file and
>> changed abbrev.el to use it? Also this would allow to reuse that
>> functionality in other places where obarrays are used.
>
> In principle I like that. But I had a quick look at abbrev.el and I
> couldn't find the code you're referring to.
> Exactly what functionality would you like to move?

For example creation of obarray from make-abbrev-table could be
extracted to separate method. So:
(let ((table (make-vector (or size 59) 0)))

would turn into:
;; in obarray-lib.el:
(defun obarray-make (&optional size)
  "Return a new obarray of size `SIZE' (defaults to 59).
The value 59 is an arbitrary prime number."
  (make-vector (or size 59) 0))

;; in abbrev.el/make-abbrev-table:
(let ((table (obarray-make)))
-------

Similarly:
(defun abbrev-table-p (object)
  "Return non-nil if OBJECT is an abbrev table."
  (and (vectorp object)
       (numberp (abbrev-table-get object :abbrev-table-modiff))))

into:
(defun obarray-p (object)
  "Return t if `OBJECT' is an obarray."
  (and (vectorp object)
       (< 0 (length object))
       ;; should check also table values?
       ))

(defun abbrev-table-p (object)
  "Return non-nil if OBJECT is an abbrev table."
  (and (obarray-p object)
       (numberp (abbrev-table-get object :abbrev-table-modiff))))
------

IMHO the code would be also a bit more readable with the following
functions:
;; not "map", because "map"s return values, this one not
(defun obarray-foreach (fn table)
  "Call function `FN' on every symbol in obarray `TABLE'."
  (mapatoms fn table))

(defun obarray-get (name table)
  "Return symbol with `NAME' from obarray `TABLE' or nil."
  (intern-soft name table))

(defun obarray-put (name table)
  "Return symbol with `NAME' form obarray `TABLE' or nil.
Create and add the symboly if doesn't exist."
  (intern name table))
------

This way or another obarray's internals should not be abbrev's
concern. It should just use its API to implement own functionality. This
also ease testing, because both parts can be tested separately. Also
obarray functions could be reused in other places - quick grep shows
that obarray-make would be common.



  reply	other threads:[~2015-11-01 22:17 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-31 13:21 Separating obarray handling from abbrevs Przemysław Wojnowski
2015-11-01 13:11 ` Artur Malabarba
2015-11-01 22:17   ` Przemysław Wojnowski [this message]
2015-11-02 20:21     ` John Wiegley
2015-11-08 18:50       ` Przemysław Wojnowski
2015-11-08 18:54         ` Eli Zaretskii
2015-11-08 19:09           ` Przemysław Wojnowski
2015-11-08 19:59             ` Eli Zaretskii
2015-11-08 21:05         ` Artur Malabarba
2015-11-08 21:17           ` Przemysław Wojnowski
2015-11-09  9:38             ` Stephen Leake
2015-11-08 21:36           ` Przemysław Wojnowski
2015-11-09  0:29             ` Artur Malabarba
2015-11-09 18:24               ` Przemysław Wojnowski
2015-11-09 23:12                 ` Nicolas Petton
2015-11-09 23:18                   ` John Wiegley
2015-11-10 20:10                   ` Przemysław Wojnowski
2015-11-10 20:32                     ` John Wiegley
2015-11-10 20:37                       ` Eli Zaretskii
2015-11-10 20:54                         ` Przemysław Wojnowski
2015-11-11  4:27                           ` Ken Raeburn
2015-11-11 16:51                         ` Nicolas Petton
2015-11-10 20:39                       ` Przemysław Wojnowski
2015-11-10 21:55                         ` Artur Malabarba
2015-11-10 22:19                           ` Drew Adams
2015-11-10 22:26                           ` John Wiegley
2015-11-11  3:31                         ` Eli Zaretskii
2015-11-11  5:08                           ` Drew Adams
2015-11-11 10:40                         ` David Kastrup
2015-11-11 16:50                       ` Nicolas Petton
2015-11-11 16:56                       ` Nicolas Petton
2015-11-11 16:57                         ` John Wiegley
2015-11-19 23:23                           ` Nicolas Petton
2015-11-20  0:13                             ` John Wiegley
2015-11-20  1:01                               ` Artur Malabarba
2015-11-20  7:52                                 ` Przemysław Wojnowski
2015-11-10 22:01                     ` Nicolas Petton

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r3k95ppo.fsf@cumego.com \
    --to=esperanto@cumego.com \
    --cc=bruce.connor.am@gmail.com \
    --cc=emacs-devel@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.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.