1

I have some functions that depend on smart-parens code.

(defun outer-paren ()
  "Move point to the  outermost parenthesis."
  (interactive)
  (ignore-errors
    (while t
      (up-list)))
  (sp-backward-sexp))

(defun func ()
  (let ((start (outer-paren))
    (end (sp-forward-sexp)))
    (narrow-to-region start end)))

The above func code returns a plist set by let:

(:beg 145 :end 163 :op "「" :cl "」" :prefix "" :suffix "") (:beg 145 :end 163 :op "「" :cl "」" :prefix "" :suffix "")

This causes an error from narrow-to-region() when func is called.

(wrong-type-argument integer-or-marker-p (:beg 145 :end 163 :op "「" :cl "」" :prefix "" :suffix ""))

How do I access start and end as variables within func?

2

You are trying to use the values returned by functions outer-paren and sp-forward-sexp, instead of the positions they move to.

The error message tells you that narrow-to-region expects buffer positions - numbers or markers. So clearly your values of start and end aren't such. They aren't numbers or markers because functions outer-paren and sp-forward-sexp return something other than the position they move to.

Don't confuse the side effect of a Lisp function with its return value.

(defun func ()
  (let ((start  (progn (outer-paren) (point)))
        (end    (progn (sp-forward-sexp) (point))))
    (narrow-to-region start end)))
| improve this answer | |
2

I think you need to access the property values that narrow to region needs.

  (use-package smartparens)
  (defun outer-paren ()
    "Move point to the  outermost parenthesis."
    (interactive)
    (ignore-errors
      (while t
        (up-list)))
    (sp-backward-sexp))

  (defun func ()
    (let ((start (outer-paren))
      (end (sp-forward-sexp)))
      (narrow-to-region (plist-get start :beg ) (plist-get start :end ))))
  (func)
(setq pl '(:beg 121 :end 141))
(plist-get pl :beg)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.