all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* more lexical/dynamic trouble
@ 2021-10-17 11:58 Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-18  7:50 ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-17 11:58 UTC (permalink / raw)
  To: help-gnu-emacs

With lexical binding, and a closure, I was able to remove two
defvars, i.e. global variables (so they were special/dynamic as
well).

But for some reason first it wouldn't work ... then I saw the
file in the `buffer-menu' /d in red! So the whole file was
actually under dynamic binding despite the use of

-*- lexical-binding: t

in the first line!

Reason, I had put it LAST, not first! Look below how it
should look!

Also: see the use of `declare-function' to shut up the
byte-compiler!

Also: beware that `checkdoc-current-buffer' reports

  The first line should be of the form: ";;; package --- Summary"

which is incorrect if you'd like `lexical-binding' and the
reason I put it at the back of that line initially (which
doesn't work).

OK, should check out my other packs and see if they are
special/dynamic as well, and if there are `defvar' to prune
there as well ...

;;; -*- lexical-binding: t -*- buc.el --- move between buffers based on category
;;;
;;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;;; Created: 2021-05-23
;;; Keywords: docs, files
;;; License: GPL3+
;;; Package-Requires: ((cl-lib "1.0"))
;;; URL: https://dataswamp.org/~incal/emacs-init/buc.el
;;; Version: 1.0.4
;;;
;;; Commentary:
;;;
;;; This package enables you to move between similar buffers.
;;; So far I have only found one use case for it, namely
;;; accessing man pages - try `man-buc' below.
;;;
;;; The general idea behind the interface is to present
;;; alternatives based on your recent answers to the same
;;; questions. The alternatives are sorted to present you with
;;; the most relevant one first. You pick an alternative by
;;; hitting a single key. If your desired choice is not among
;;; the alternatives, start typing, that will bypass the
;;; interface and the default interface will be used as
;;; a fallback. (But technically it is not a fallback, rather
;;; the interfaces are cooperating covering different parts of
;;; one problem.)
;;;
;;; Note that If you count the number of keypresses you see
;;; the advantage with this package. When the buc interface is
;;; used, the count is much lower, since making a choice
;;; involves hitting a single key or combination. But even
;;; when it is not used, the count still is not higher than
;;; what you would use anyway, since the default interface
;;; immediately comes to life and utilizes the first keydown
;;; as its first input char. Again, try `man-buc' to see how
;;; it works first hand.
;;;
;;; Or take a look at this screenshot:
;;;
;;;   https://dataswamp.org/~incal/dumps/buc.png
;;;
;;; The principle behind the interface is similar to that of
;;; a computer hardware memory cache: proximity in space and
;;; time, with updates on every single access.
;;;
;;; The interface is an hybrid between the GUI and CLI style,
;;; only the GUI "icons" are here words! Some say icons are
;;; more intuitive than words. Well, that is were we agree to
;;; disagree - perhaps that holds for infants but not to
;;; adults who have spent a HUGE part of their life reading
;;; and writing.
;;;
;;; Because we believe intuition is an acquired skill - just
;;; like everything else.
;;;
;;; Code:

(require 'cl-lib)

(defun buffer-names ()
  "Get the names of all open buffers, as strings."
  (mapcar #'buffer-name (buffer-list)) )

(defun extract-strings (strs match)
  "From STRS, get a list with the parts that MATCH."
  (remove nil (mapcar (lambda (s)
                        (when (string-match match s)
                          (match-string 1 s) ))
                      strs) ))

(declare-function get-ps                   load-file-name)
(declare-function navigate-buffer-category load-file-name)

(let*((nav-keys    '(?\r ?\s ?\t ?\d ?\C-j ?\C-k ?\C-l ?\C-u ?\C-o ?\C-p))
      (nav-keys-str (split-string (key-description nav-keys))) )
  (defun get-ps (names)
    "Make the prompt-string, with NAMES."
    (let ((k  -1)
          (s " [") )
      (dolist (e names (concat s "] "))
        (setq s (format "%s %s:%s " s (nth (cl-incf k) nav-keys-str) e)) )))

  (defun navigate-buffer-category (prefix &optional bad-key &rest args)
    "Display all buffers that start with PREFIX.
If none of the offered buffers are chosen by the user's keystroke,
evaluate (BAD-KEY ARGS)."
    (let ((pages (extract-strings (buffer-names)
                                  (format "%s%s" prefix "\\(.*\\)\\*") )))
      (if pages
          (let*((ps         (get-ps pages))
                (key        (read-key ps))
                (page-index (cl-position key nav-keys))
                (page       (when page-index
                              (nth page-index pages) )))
            (if (= key 7)
                (message "quit")
              (if page
                  (switch-to-buffer (format "%s%s*" prefix page))
                (when bad-key
                  (apply bad-key `(,@args ,key)) ))))
        (if bad-key
            (apply bad-key args)
          (error "Empty category, no fallback function") )))))

(defun switch-to-type (ps fun &optional key)
  "Ask for a string with the prompt-string PS.
Use the string as input to FUN.
If KEY, it'll be the first KEY of the string, auto-inserted."
  (apply fun (list (read-string ps (and key (char-to-string key))))) )

(defun man-buc ()
  "Show man pages.
If you start typing, you get the common prompt."
  (interactive)
  (navigate-buffer-category "*Man " #'switch-to-type "[buc] man page: " 'man) )

(provide 'buc)
;;; buc.el ends here

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: more lexical/dynamic trouble
  2021-10-17 11:58 more lexical/dynamic trouble Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-18  7:50 ` Michael Heerdegen
  2021-10-18 13:55   ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2021-10-18  7:50 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> Reason, I had put it LAST, not first! Look below how it should look!

I don't know what is happening to you and why, but there is no such
rule.  See the Emacs Elisp sources for examples.

Michael.




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

* Re: more lexical/dynamic trouble
  2021-10-18  7:50 ` Michael Heerdegen
@ 2021-10-18 13:55   ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-10-18 18:58     ` Tassilo Horn
  2021-10-18 20:54     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 8+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-10-18 13:55 UTC (permalink / raw)
  To: help-gnu-emacs

>> Reason, I had put it LAST, not first! Look below how it should look!
> I don't know what is happening to you and why, but there is no such
> rule.  See the Emacs Elisp sources for examples.

My crystal ball mumbled something about a missing "-*-" at the end.


        Stefan




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

* Re: more lexical/dynamic trouble
  2021-10-18 13:55   ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-10-18 18:58     ` Tassilo Horn
  2021-10-18 20:59       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-18 20:54     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 8+ messages in thread
From: Tassilo Horn @ 2021-10-18 18:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

>>> Reason, I had put it LAST, not first! Look below how it should look!
>> I don't know what is happening to you and why, but there is no such
>> rule.  See the Emacs Elisp sources for examples.
>
> My crystal ball mumbled something about a missing "-*-" at the end.

Very likely.  I never edit those lines manually but always use `M-x
add-file-local-variable-prop-line RET'.

Bye,
Tassilo



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

* Re: more lexical/dynamic trouble
  2021-10-18 13:55   ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-10-18 18:58     ` Tassilo Horn
@ 2021-10-18 20:54     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-18 20:54 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

>>> Reason, I had put it LAST, not first! Look below how it
>>> should look!
>>
>> I don't know what is happening to you and why, but there is
>> no such rule. See the Emacs Elisp sources for examples.
>
> My crystal ball mumbled something about a missing "-*-" at
> the end.

You are right :)

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: more lexical/dynamic trouble
  2021-10-18 18:58     ` Tassilo Horn
@ 2021-10-18 20:59       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-10-18 22:58         ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-18 20:59 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn wrote:

>>> I don't know what is happening to you and why, but there
>>> is no such rule. See the Emacs Elisp sources for examples.
>>
>> My crystal ball mumbled something about a missing "-*-" at
>> the end.
>
> Very likely. I never edit those lines manually but always
> use `M-x add-file-local-variable-prop-line RET'.

Oh, yeah? Well, this happened because it isn't intuitive to
have a delimiter between something and nothing ...

Make `lexical-binding' t by default everywhere and
introduce/enforce explicit use, i.e. slet/let/dlet ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: more lexical/dynamic trouble
  2021-10-18 20:59       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-10-18 22:58         ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-10-18 23:12           ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-10-18 22:58 UTC (permalink / raw)
  To: help-gnu-emacs

> Make `lexical-binding' t by default everywhere and

We're working on it, but it takes time.  Some of that time is spent
waiting for other people to update their code (i.e. not very
compressible, even with a very large number of monkeys typing furiously
on their keyboards).

Emacs-28's own code uses lexical-binding everywhere.
But we're still far from that in third party packages.


        Stefan




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

* Re: more lexical/dynamic trouble
  2021-10-18 22:58         ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-10-18 23:12           ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-10-18 23:12 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

>> Make `lexical-binding' t by default everywhere and
>
> We're working on it, but it takes time. Some of that time is
> spent waiting for other people to update their code (i.e.
> not very compressible, even with a very large number of
> monkeys typing furiously on their keyboards).
>
> Emacs-28's own code uses lexical-binding everywhere.
> But we're still far from that in third party packages.

Yes, I get it, no rush. Everything always in time ...

Maybe the byte-compiler and/or `checkdoc' could warn and bug
people about it.

BTW they could also tell that -*- without a closing -*- doesn't
do anything ...

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2021-10-18 23:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-17 11:58 more lexical/dynamic trouble Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-18  7:50 ` Michael Heerdegen
2021-10-18 13:55   ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-10-18 18:58     ` Tassilo Horn
2021-10-18 20:59       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-18 22:58         ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-10-18 23:12           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-18 20:54     ` Emanuel Berg via Users list for the GNU Emacs text editor

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.