Skip to main content
added
Source Link
Muihlinn
  • 2.7k
  • 1
  • 15
  • 22

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point))
            (newline))))
 

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use anything else that you may prefer.

thing-at-point will automagically get the specified kind of thing around point; as save-excursion will save point, it'll return to it after executing its body, but saved point may not be the end of word, so you may want to forward-word (M-f) which was left out for clarity.

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point))
            (newline))))
 

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use anything else that you may prefer.

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point))
            (newline))))

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use anything else that you may prefer.

thing-at-point will automagically get the specified kind of thing around point; as save-excursion will save point, it'll return to it after executing its body, but saved point may not be the end of word, so you may want to forward-word (M-f) which was left out for clarity.

added 157 characters in body
Source Link
Muihlinn
  • 2.7k
  • 1
  • 15
  • 22

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point))
            (newline))))

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use anything else that you may prefer.

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point)))))

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use anything else that you may prefer.

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point))
            (newline))))

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use anything else that you may prefer.

added 19 characters in body
Source Link
Muihlinn
  • 2.7k
  • 1
  • 15
  • 22

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point)))))

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use whateveranything else that you wantmay prefer.

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert word-at-point))))

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use whatever you want.

As you're not going to use the region between point and mark, consider another approach using save-excursion, like this one:

(defun auto-import-word-at-point()
    "Autoimport word at point."
    (interactive)
    (let ((word-at-point (thing-at-point 'word)))
        (save-excursion
            (goto-line 2)
            (insert (concat "import " word-at-point)))))

It will copy the thing at point, goto line 2, insert it there and restore things. Bind to whatever you want and it's ready to go, thing-at-point is just a way to obtain data, but can use anything else that you may prefer.

Source Link
Muihlinn
  • 2.7k
  • 1
  • 15
  • 22
Loading