help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: [External] : Any packages using ThingAtPointPlus for activation?


From: Jean Louis
Subject: Re: [External] : Any packages using ThingAtPointPlus for activation?
Date: Thu, 5 Jan 2023 08:42:26 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Eduardo Ochs <eduardoochs@gmail.com> [2023-01-04 19:05]:
> Hi Jean and all,
> 
> for the sake of completeness, here is the prototype that I wrote:
> 
>   http://angg.twu.net/elisp/eev-rcd-tap-1.el

I have been testing it. Thanks.

I am interested in quick, user friendly way of invoking functions with
multiple variations by using single key, not necessarily only on thing
at point, there are variations involved. A "word" may be special word
like database table name, I may need or want to browse the entries
straight.

I have often functions like:

(rcd-db-get-entry "hyobjects" "hyobjects_link" id hs-db) 
as that one fetch value of column "hyobjects_link" from table
"hyobjects" by unique key ID from database "hs-db".

And Emacs will not recognize "hyobjects" but my function can do that.

General idea is to expand or bypass Hyperbole's usage of a single key
to become smart in various context.

There is function `read-multiple-choice' (blocking the interface)
which can be used for few choices. 

If there is active region, I wish to choose if to capture it or do
what else with it.

So I have made `read-multiple-choice' to be automatic:

(defun rcd-multiple-choice-by-listo (list rcd-function &optional prompt 
description quit-on-any)
  "Run RCD-FUNCTION on results of multiple choice LIST of strings.

It uses `q' char to quit thus its value will not be used.
PROMPT is optional just as DESCRIPTION.

QUIT-ON-ANY will not return to main menu after running the function."
  (let* ((prompt (or prompt "Choose: "))
         (choices '((?q "Quit")))
         (key ?b)
         (quit))
    (mapc (lambda (item)
            (when (= key ?q) (setq key (1+ key)))
            (push (list key item description) choices)
            (setq key (1+ key)))
          (seq-sort 'string< list))
    (while (not quit)
      (let* ((resize-mini-windows t) ;; TODO maybe not needed, rather setting 
max-mini-window-height?
             (selection (read-multiple-choice prompt (reverse choices)))
             (new-key (car selection))
             (value (cadr selection)))
        (setq key new-key)
        (when (or quit-on-any (= ?q key)) (setq quit t))
        (unless (= ?q new-key)
          (funcall rcd-function value))))))

Then I can do something like:

(defun rcd-db-region-choice ()
  (when (region-active-p)
    (let ((region (rcd-region-string)))
      (rcd-multiple-choice-by-list
       '("Search Hyperscope" "Search people" "Capture region" "rgrep") 
       (lambda (arg) 
         (cond ((string= arg "Search Hyperscope") (hyperscope-by-name nil 
region))
               ((string= arg "Search people") (cf-people-by-name region))
               ((string= arg "Capture region") (hyperscope-capture-region))
               ((string= arg "rgrep") (rgrep-current-word-in-el-project))
               (t (message "%s" arg) (sleep-for 2))))
       "What to do with region?" nil t))))

The above concept will be added to things at point, as if there is
region, there may be special things to choose.

That get included:

(defun hyperscope-action-button ()
  (interactive)
  (cond ((region-active-p) (rcd-db-region-choice))
        ((thing-at-point 'uuid) (rcd-db-uuid-action (thing-at-point 'uuid)))
        ((thing-at-point 'url) (browse-url (thing-at-point 'url)))
        ((thing-at-point 'email) (rcd-write-email user-full-name 
user-mail-address (thing-at-point 'email) (thing-at-point 'email)))
        ((and (thing-at-point 'symbol) (boundp (symbol-at-point))) 
(find-variable (symbol-at-point)))
        ((and (thing-at-point 'symbol) (fboundp (symbol-at-point))) 
(find-function (symbol-at-point)))
        ((thing-at-point 'number) (hyperscope-isolate (thing-at-point 'number)))
        ((thing-at-point 'word) (cond ((hyperscope-tap-table) 
(hyperscope-visit-table (thing-at-point 'word)))
                                      (t (funcall (cond ((fboundp 
'wordnut-search) 'wordnut-search)
                                                        ((fboundp 
'dictionary-search) 'dictionary-search))
                                                  (thing-at-point 'word)))))
        (t (rcd-message "Hyperscope action not defined."))))

(keymap-global-set "M-RET" #'hyperscope-action-button) 

Concept is decades old from Hyperbole. It is to unify common functions
to single key, making the key "smart" by context.

Example of contexts:

- Cursor in mail mode before the line "--text follows this line--"
  where line begins with To, Bcc, Cc, then it should try to expand
  e-mail aliases

- Cursor or point on known e-mail address, that exist in database, ask
  user if to jump to profile or send e-mail?

- Cursor on unknown e-mail address, or phone number, or similar, enter
  in the database first.

- Cursor on known phone number, display contact's name, decide if to
  initiate call, SMS, XMPP, send E-mail, etc. 

  I initiate calls by using:

  (defun termux-call (number)
  "Call NUMBER"
  (let ((command (concat "(am start -a android.intent.action.CALL -d tel:" 
number)))
    (termux/send-command command)))


-- 
Jean

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

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



reply via email to

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