Giter Site home page Giter Site logo

Comments (3)

noctuid avatar noctuid commented on September 2, 2024

Maybe new commands or an option could be added, but I think the default commands should always act on atoms. For now, you could use general-predicated-dispatch (or the equivalent if you don't use general), for example, to create your own version that behaves differently in comments.

from lispyville.

bpstahlman avatar bpstahlman commented on September 2, 2024

Hmm... My reading of the relevant section in the Emacs manual leaves me nearly convinced that comments aren't considered "atoms" in the lisp sense. I get the sense that comment and code spaces are orthogonal, and that the concepts of "list" and "atom" have meaning only in the latter.

At any rate, I have atom-motions disabled for now because it makes editing comments so painful. Thanks for the suggested workaround. I'll try to look at general-predicated-dispatch (and General, more generally) when I get some free time...

from lispyville.

noctuid avatar noctuid commented on September 2, 2024

Here is a self contained example (general.el not needed):

(cl-defmacro general-predicate-dispatch
    (fallback-def &rest defs
                  &key docstring
                  &allow-other-keys)
  (declare (indent 1))
  "Create a menu item that will run FALLBACK-DEF or a definition from DEFS.
DEFS consists of <predicate> <definition> pairs. Binding this menu-item to a key
will cause that key to act as the corresponding definition (a command, keymap,
etc) for the first matched predicate. If no predicate is matched FALLBACK-DEF
will be run. When FALLBACK-DEF is nil and no predicates are matched, the keymap
with the next highest precedence for the pressed key will be checked. DOCSTRING
can be specified as a description for the menu item."
  ;; remove keyword arguments from defs and sort defs into pairs
  (let ((defs (cl-loop for (key value) on defs by 'cddr
                       unless (keywordp key)
                       collect (list key value))))
    `'(menu-item
       ,(or docstring "") nil
       :filter (lambda (&optional _)
                 (cond ,@(mapcar (lambda (pred-def)
                                   `(,(car pred-def) ,(cadr pred-def)))
                                 defs)
                       (t ,fallback-def))))))

(define-key lispyville-mode-map
  [remap evil-forward-word-begin]
  (general-predicate-dispatch #'lispyville-forward-atom-begin
    (lispy--in-string-or-comment-p) #'evil-forward-word-begin))

(lispy--in-string-or-comment-p) could be replaced with (lispy--in-comment-p) or whatever.

from lispyville.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.