Lisp HUG Maillist Archive

Binding cmd-e on Mac?

I've been trying to make Cmd-e on Mac set up the current find string.  
I've written an editor command that will do that, but it doesn't want  
to bind to that key.

Here's the command:

(defcommand "Use Selection for Find" (p)
      "Makes the selection the current find string"
      "Makes the selection the current find string"
   (declare (ignore p))
   (when (region-active-p)
     (let ((pt-string (points-to-string (current-point) (current- 
mark))))
       (push pt-string lispworks-tools::*editing-interface-find- 
strings*))))

and I'm binding it with:

(mac-bind-key "Use Selection for Find" "Hyper-e")

in my lispworks-init.lisp. There seems to be something special about  
Cmd-keys. command-to-key reports the binding correctly, but I can't  
type Cmd-e for key-to-command.

I don't want to set the preference to use Cmd as Meta, either. I think  
that would be too confusing.

Ideally, I'd rather add a menu item named "Use Selection for Find",  
but I don't see how to do that.

Any ideas or suggestions?

Thanks.

  - Stoney

-- 
Stonewall Ballard
stoney@sb.org           http://stoney.sb.org/


Re: Binding cmd-e on Mac?

Hi Stoney,

On Mar 16, 2009, at 5:38 PM, Stonewall Ballard wrote:

> I don't want to set the preference to use Cmd as Meta, either. I  
> think that would be too confusing.
>
> Ideally, I'd rather add a menu item named "Use Selection for Find",  
> but I don't see how to do that.
>
> Any ideas or suggestions?


I came to the same conclusion: no supported way to bind Mac command  
keys. As usual, if there is no supported way, you can usually still  
find a way :). But no guarantee it will always work with future  
releases.

What I did was to add my own menu to the editor and listener with all  
the commands I wanted to have command key accelerators. See code  
below. Note I also deleted the editor View menu because I did not find  
it to be useful.

John DeSoi, Ph.D.


=====

(lw:define-action "CAPI Create Interface" "customize interface"  
'customize-interface)

(defvar *my-custom-menu-title* "Toolbox")

(defun customize-interface (iface)
   (let ((menus (capi:interface-menu-bar-items iface))
         (custom nil))
     (typecase iface
       (lispworks-tools:editor
        (when-let (view (find "View" menus :key #'capi-internals:menu- 
title :test #'string-equal))
          (setf menus (remove view menus)))
        (setf custom (editor-toolbox-menu)))
       (lispworks-tools:listener
        (setf custom (listener-toolbox-menu))))
     (when custom
       (when-let (old-custom (find *my-custom-menu-title* menus :key  
#'capi-internals:menu-title :test #'string-equal))
         (setf old-custom (remove old-custom menus)))
       (setf (capi:interface-menu-bar-items iface) ;add custom menu  
after file and edit
             (append (list (first menus) (second menus) custom)  
(nthcdr 2 menus))))))



; custom menu we add to the editor mainly so we can use command keys  
we want
(defun editor-toolbox-menu ()
   (make-instance
            'capi:menu :title *my-custom-menu-title*
            :callback-type :interface
            :items (list
                    (make-instance
                     'capi:menu-component
                     :name :shortcuts
                     :items (list
                             (make-instance
                              'capi:menu-item
                              :callback-type :none
                              :title "Listener"
                              :accelerator #\l
                              :callback (lambda () (capi:find- 
interface 'lw-tools:listener)))))
                    (make-instance
                     'capi:menu-component
                     :name :editor-tools
                     :items (list
                             (make-instance
                              'capi:menu-item
                              :title "Compile Defun"
                              :accelerator #\j
                              :callback (lambda (ed) (exec-in-editor- 
buffer ed 'my-compile-defun-command nil)))
                             (make-instance
                              'capi:menu-item
                              :title "Compile Buffer"
                              :accelerator #\b
                              :callback (lambda (ed) (exec-in-editor- 
buffer ed 'my-compile-buffer-command nil))))))))



(defun listener-toolbox-menu ()
   (make-instance
            'capi:menu :title *my-custom-menu-title*
            :callback-type :interface
            :items (list
                    (make-instance
                     'capi:menu-component
                     :name :shortcuts
                     :items (list
                             (make-instance
                              'capi:menu-item
                              :callback-type :none
                              :title "Editor"
                              :accelerator #\l ;same key to toggle  
between editor and listener
                              :callback (lambda () (capi:find- 
interface 'lw-tools:editor))))))))




Updated at: 2020-12-10 08:41 UTC