emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Separating obarray handling from abbrevs


From: Przemysław Wojnowski
Subject: Re: Separating obarray handling from abbrevs
Date: Sun, 01 Nov 2015 23:17:55 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Artur Malabarba <address@hidden> writes:
> 2015-10-31 13:21 GMT+00:00 Przemysław Wojnowski <address@hidden>:
>> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]