all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Jean: buc.el ready (actually, now when I understand it again, it isn't a bad idea at all!)
@ 2021-06-08  8:12 Emanuel Berg via Users list for the GNU Emacs text editor
  2021-06-08 14:28 ` buc.el ready Jean Louis
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-06-08  8:12 UTC (permalink / raw)
  To: help-gnu-emacs

Jean, or anyone else, take a look. Is the pack ready? [code
also yanked last in mail]

  https://dataswamp.org/~incal/emacs-init/buc.el

I went thru it and it is actually a very good an simple idea,
I don't know why I suddenly didn't understand it's purpose and
thought it complicated...

I'm unsure tho if the documentation probably doesn't make
anything clearer to a lot of people, right?

Perhaps should add an example run...

What do you think?

Is it OK now as an Elisp package?

;;; buc.el --- move between buffers based on category -*- lexical-binding: t
;;;
;;; Commentary:
;;;
;;; 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: 2.0.0
;;;
;;; Move between similar buffers. So far I have only found one
;;; use case for this, 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 isn't among
;;; the alternatives, start typing, that will bypass the
;;; interface and the default interface will be used as
;;; a fallback. (But technically it isn't a fallback, rather
;;; the interfaces are cooperating covering different parts of
;;; one problem, and buc was programmed with this situation
;;; in mind.)
;;;
;;; If you'd count the number of keypresses you'd see the
;;; advantage with this package. When the buc interface is
;;; used, the count is much lower; when it isn't used, the
;;; count still isn't higher than what you'd use anyway.
;;; 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 cache: proximity in space and time,
;;; with updates on every single access.
;;;
;;; The interface is an hybrid between the GUI and CLI style,
;;; the GUI "icons" here being words! Some say icons are more
;;; intuitive. That's were we agree to disagree, that perhaps
;;; holds for infants (and illiterates) but not to adults
;;; who've literally spent a substantial 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)) )

(defvar nav-keys     nil "The keys used to select buffers.")
(defvar nav-keys-str nil "Descriptions of the buffer-select keys.")

(setq nav-keys     '(?\r ?\s ?\t ?\d ?\C-j ?\C-k ?\C-l ?\C-u ?\C-o ?\C-p))
(setq nav-keys-str  (split-string (key-description nav-keys)))

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

(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 and 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
         `(,(read-string ps (when key (char-to-string key)) nil)) ))

(defun man-buc ()
  "Show man pages.  If you type, 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] 5+ messages in thread

* Re: buc.el ready
  2021-06-08  8:12 Jean: buc.el ready (actually, now when I understand it again, it isn't a bad idea at all!) Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-06-08 14:28 ` Jean Louis
  2021-07-06  9:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-07-06 15:53   ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 5+ messages in thread
From: Jean Louis @ 2021-06-08 14:28 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-06-08 11:13]:
> Jean, or anyone else, take a look. Is the pack ready? [code
> also yanked last in mail]
> 
>   https://dataswamp.org/~incal/emacs-init/buc.el
> 
> I went thru it and it is actually a very good an simple idea,
> I don't know why I suddenly didn't understand it's purpose and
> thought it complicated...

;;; buc.el --- move between buffers based on category -*- lexical-binding: t
;;;
;;; Commentary:
;;;
;;; 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: 2.0.0

Your "Commentary" comes too early there.

Why not read: (info "(elisp) Simple Packages")	

Additionally you have not provided a license. "GPL3+" is some kind of
a tag, it is not a license and does not comply to GPL3 licensing
requirements. Use C-h C-c to find out "How to apply"

> I'm unsure tho if the documentation probably doesn't make anything
> clearer to a lot of people, right?

I was never reading documentation inside of package before some
years. I was reading description lines from M-x package-list-packages
and information about the package. Why should a user go into the
source, unless it is some programming library.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



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

* Re: buc.el ready
  2021-06-08 14:28 ` buc.el ready Jean Louis
@ 2021-07-06  9:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-07-06 15:53   ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-06  9:39 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> ;;; buc.el --- move between buffers based on category -*- lexical-binding: t
> ;;;
> ;;; Commentary:
> ;;;
> ;;; 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: 2.0.0
>
> Your "Commentary" comes too early there.

Ah, nice catch, thanks!

Now what do you think? Revised the documentation a little bit
as well.

;;; buc.el --- move between buffers based on category -*- lexical-binding: t
;;;
;;; 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.2
;;;
;;; 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)) )

(defvar nav-keys     nil "The keys used to select buffers.")
(defvar nav-keys-str nil "Descriptions of the buffer-select keys.")

(setq nav-keys     '(?\r ?\s ?\t ?\d ?\C-j ?\C-k ?\C-l ?\C-u ?\C-o ?\C-p))
(setq nav-keys-str  (split-string (key-description nav-keys)))

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

(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 and 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
                            (when key
                              (char-to-string key))
                            nil) )))

(defun man-buc ()
  "Show man pages.  If you type, 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] 5+ messages in thread

* Re: buc.el ready
  2021-06-08 14:28 ` buc.el ready Jean Louis
  2021-07-06  9:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-06 15:53   ` Stefan Monnier via Users list for the GNU Emacs text editor
  2021-07-06 16:18     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-07-06 15:53 UTC (permalink / raw)
  To: help-gnu-emacs

> ;;; buc.el --- move between buffers based on category -*- lexical-binding: t
> ;;;
> ;;; Commentary:
> ;;;
> ;;; 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: 2.0.0

Three semi-colons (and more) are used for outline/section headers, so
it's right for "Commentary:" but not for the other lines above, which
should only have two semi-colons.


        Stefan




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

* Re: buc.el ready
  2021-07-06 15:53   ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2021-07-06 16:18     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-06 16:18 UTC (permalink / raw)
  To: help-gnu-emacs

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

>> ;;; buc.el --- move between buffers based on category -*- lexical-binding: t
>> ;;;
>> ;;; Commentary:
>> ;;;
>> ;;; 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: 2.0.0
>
> Three semi-colons (and more) are used for outline/section
> headers, so it's right for "Commentary:" but not for the
> other lines above, which should only have two semi-colons.

I know/I've seen that but that looks so ugly. But OK...

What do you think of the idea BTW?

;;; buc.el --- move between buffers based on category -*- lexical-binding: t
;;
;; 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.3
;;
;;; 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)) )

(defvar nav-keys     nil "The keys used to select buffers.")
(defvar nav-keys-str nil "Descriptions of the buffer-select keys.")

(setq nav-keys     '(?\r ?\s ?\t ?\d ?\C-j ?\C-k ?\C-l ?\C-u ?\C-o ?\C-p))
(setq nav-keys-str  (split-string (key-description nav-keys)))

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

(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 and 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
                            (when key
                              (char-to-string key))
                            nil) )))

(defun man-buc ()
  "Show man pages.  If you type, 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] 5+ messages in thread

end of thread, other threads:[~2021-07-06 16:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-08  8:12 Jean: buc.el ready (actually, now when I understand it again, it isn't a bad idea at all!) Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-08 14:28 ` buc.el ready Jean Louis
2021-07-06  9:39   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-06 15:53   ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-07-06 16:18     ` 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.