Changeset 15886


Ignore:
Timestamp:
Aug 29, 2013, 9:51:15 PM (6 years ago)
Author:
gz
Message:

Added function HI:COMMANDS-AND-BINDINGS, returns a list of (command . keys-for-the-command) of editor commands available in buffers created with modes which are the value of the default-modes hemlock variable. (The values returned are objects, not strings. A command object can be converted to a string with HI:COMMAND-NAME and/or HI:COMMAND-DOCUMENTATION. A key can be converted to a string with HI:PRETTY-KEY-STRING).

Made cocoa-editor set default-mode rather than overriding it.

Location:
trunk/source/cocoa-ide
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/cocoa-editor.lisp

    r15872 r15886  
    28982898(defvar *last-document-created* nil)
    28992899
     2900(setf (hemlock::value hemlock::default-modes) '("Lisp" "Editor"))
     2901
     2902
    29002903(objc:defmethod #/init ((self hemlock-editor-document))
    29012904  (let* ((doc (call-next-method)))
     
    29042907                              (make-hemlock-buffer
    29052908                               (lisp-string-from-nsstring
    2906                                 (#/displayName doc))
    2907                                :modes '("Lisp" "Editor")))))
     2909                                (#/displayName doc))))))
    29082910    (with-slots (encoding) doc
    29092911      (setq encoding (or (get-default-encoding) #$NSISOLatin1StringEncoding)))
  • trunk/source/cocoa-ide/hemlock/src/interp.lisp

    r12430 r15886  
    251251;;;
    252252(defun get-current-binding (key)
    253   (let ((buffer *current-buffer*)
     253  (let ((buffer (current-buffer))
    254254        (t-bindings nil) res t-res)
    255255    (multiple-value-setq (res t-res) (get-binding-in-buffer key buffer))
     
    381381    result))
    382382
     383;;; COMMANDS-AND-BINDINGS -- Public
     384;;;
     385;;; Return a list of (command . key-bindings), for use in help.  Looks only at bindings
     386;;; in modes in "Default Modes" variable, doesn't require current buffer.
     387;;;
     388(defun commands-and-bindings (&optional (modes (value hemlock::default-modes)))
     389  (when (some #'stringp modes)
     390    (setq modes (mapcar (lambda (m) (if (stringp m) (get-mode-object m) m)) modes)))
     391  (loop for cmd in (string-table-values *command-names*)
     392    as bindings = (command-bindings cmd)
     393    ;; collect unshadowed bindings
     394    as keys = (loop for (key-seq) in bindings
     395                when (eq cmd (get-binding-with-modes key-seq modes))
     396                collect key-seq)
     397    unless (or (and bindings (not keys)) ;; ignore pseudo-commands like "I-Search whatever"
     398               (command-transparent-p cmd) ;; ignore addons like exit search mode.
     399               (eq cmd (get-default-command)) ;; ignore illegal
     400               (eq cmd (get-self-insert-command));; and self insert
     401               (> (length keys) 5))      ;; ignore commmands like "Digit"
     402    collect (cons cmd keys)))
     403
     404(defun get-binding-with-modes (key modes)
     405  (or (loop for mode in modes  ;; first find minor mode binding
     406            do (when (stringp mode) (setq mode (get-mode-object mode)))
     407            thereis (and (not (mode-object-major-p mode)) (get-binding-in-mode key mode)))
     408      (loop for mode in modes  ;; next try major mode
     409            do (when (stringp mode) (setq mode (get-mode-object mode)))
     410            thereis (and (mode-object-major-p mode) (get-binding-in-mode key mode)))
     411      (get-table-entry *global-command-table* key)))
     412
     413
     414
    383415(defvar *key-event-history* (make-ring 60))
    384416
  • trunk/source/cocoa-ide/hemlock/src/package.lisp

    r15872 r15886  
    195195   #:command-bindings
    196196   #:delete-key-binding
     197   #:commands-and-bindings
    197198   #:get-command
    198199   #:map-bindings
     
    578579
    579580   ;; interp.lisp
    580    #:bind-key #:delete-key-binding #:get-command #:map-bindings
     581   #:bind-key #:delete-key-binding #:get-command #:map-bindings #:commands-and-bindings
    581582   #:make-command #:command-name #:command-bindings #:last-command-type
    582583   #:prefix-argument #:key-translation
  • trunk/source/cocoa-ide/hemlock/src/table.lisp

    r12061 r15886  
    364364    (setf (word-entry-value-node entry) value-node)))
    365365
    366 
     366(defun string-table-values (string-table)
     367  (loop with nodes = (string-table-value-nodes string-table)
     368    for i from 0 below (string-table-num-nodes string-table)
     369    collect (value-node-value (svref nodes i))))
    367370
    368371;;;; Find-Bound-Entries
Note: See TracChangeset for help on using the changeset viewer.