Skip to main content
Commonmark migration
Source Link

So I wanted to basically copy the current selection, then yanking it into find-file, as when using:

  • C-SPC: set-mark-command
  • M-w: kill-ring-save
  • C-x C-f: find-file
  • C-y: yank

While that works great, I wanted to make it into a command if possible, so I tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)

I've tried:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

##Question

Question

How could I pass the current selection/region (from C-SPC) to find-file and open the file whether it exists or not? (since usually, I recall find-file creates the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as I just did that to tinker around and see if it'll work.

So I wanted to basically copy the current selection, then yanking it into find-file, as when using:

  • C-SPC: set-mark-command
  • M-w: kill-ring-save
  • C-x C-f: find-file
  • C-y: yank

While that works great, I wanted to make it into a command if possible, so I tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)

I've tried:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

##Question

How could I pass the current selection/region (from C-SPC) to find-file and open the file whether it exists or not? (since usually, I recall find-file creates the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as I just did that to tinker around and see if it'll work.

So I wanted to basically copy the current selection, then yanking it into find-file, as when using:

  • C-SPC: set-mark-command
  • M-w: kill-ring-save
  • C-x C-f: find-file
  • C-y: yank

While that works great, I wanted to make it into a command if possible, so I tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)

I've tried:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

Question

How could I pass the current selection/region (from C-SPC) to find-file and open the file whether it exists or not? (since usually, I recall find-file creates the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as I just did that to tinker around and see if it'll work.

formatting, rewrite some sentences, clarification
Source Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

So I wanted to basically copy the current selection, then yanking it into find-file, as when using:

  • C-spaceC-SPC: set-mark-command
  • M-wM-w: kill-ring-save
  • C-x C-fC-x C-f: find-file
  • C-yC-y: yank

While that workworks great, I wanted to make it into a command if possible, so iI tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)

I've tried:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

##Question

How could I pass the current selection/region (from C-spaceC-SPC) to find-file and open the file whether it existexists or not? (since usually, I recall find-file createcreates the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as iI just did that to tinker around and see if it'll work.

So I wanted to basically copy the current selection, then yanking it into find-file, as when using:

  • C-space set-mark-command
  • M-w kill-ring-save
  • C-x C-f find-file
  • C-y yank

While that work great, I wanted to make it into a command if possible, so i tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)

I've tried:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

##Question

How could I pass the current selection/region (from C-space) to find-file and open the file whether it exist or not? (since usually, I recall find-file create the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as i just did that to tinker around and see if it'll work.

So I wanted to basically copy the current selection, then yanking it into find-file, as when using:

  • C-SPC: set-mark-command
  • M-w: kill-ring-save
  • C-x C-f: find-file
  • C-y: yank

While that works great, I wanted to make it into a command if possible, so I tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)

I've tried:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

##Question

How could I pass the current selection/region (from C-SPC) to find-file and open the file whether it exists or not? (since usually, I recall find-file creates the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as I just did that to tinker around and see if it'll work.

formatting, rewrite some sentences, clarification
Source Link

So I wanted to basically copy the current selection, (using first C-SPC, then M-w) and yanking it but to the interactiveinto find-file buffer. (using C-x C-f and then C-y)., as when using:

  • C-space set-mark-command
  • M-w kill-ring-save
  • C-x C-f find-file
  • C-y yank

That worksWhile that work great, but I wanted to make it into a function or scriptcommand if possible, so Ii tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. (and also because I didn't know how to use the default one in this particular endeavor)And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)...

II've tried before this using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

The last thing i tried was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as i'm aware (that is, it didn't work either).##Question

How could I pass the current selection/region (from C-SPCC-space) to find-file and open the file whether it exist or not? (since usually, I recall find-file create the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as Ii just did that to tinker around and see if it'll work.

So I wanted to basically copy the current selection, (using first C-SPC, then M-w) and yanking it but to the interactive find-file buffer. (using C-x C-f and then C-y).

That works great, but I wanted to make it into a function or script if possible, so I tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. (and also because I didn't know how to use the default one in this particular endeavor)

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)...

I tried before this using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

The last thing i tried was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as i'm aware (that is, it didn't work either).

How could I pass the current selection/region (from C-SPC) to find-file and open the file whether it exist or not? (since usually, I recall find-file create the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as I just did that to tinker around and see if it'll work.

So I wanted to basically copy the current selection, then yanking it into find-file, as when using:

  • C-space set-mark-command
  • M-w kill-ring-save
  • C-x C-f find-file
  • C-y yank

While that work great, I wanted to make it into a command if possible, so i tried and came up with this so far:

(define-advice kill-ring-save (:around (old-fun &rest args) highlight)
  "Save the text selection and keep the selection highlight."
  (let (deactivate-mark)
    (apply old-fun args)))

(defun find-file-region ()
  (interactive)
  (execute-extended-command nil "kill-ring-save" nil)
  (call-interactively 'find-file)
  (yank nil))

Now, I'm using this particular kill-ring-save function, mostly because I found it work better than the default one, but that's just what I noticed in my workflow. And also because i didn't know how to use the default one in this particular endeavor

So this doesn't obviously work, my guess being is that it doesn't run yank after running (call-interactively 'find-file)

I've tried:

  • using default find-file but since it require a filename and doesn't just "open with current directory of the buffer/file" like it usually do if used in the keybinding, that didn't work either.

  • was replacing (call-interactively 'find-file) with (execute-extended-command nil "find-file" nil) but it did the same thing as far as I'm aware (that is, it didn't work either).

##Question

How could I pass the current selection/region (from C-space) to find-file and open the file whether it exist or not? (since usually, I recall find-file create the file if it doesn't exist, which is what I want too).

Don't really care if it's done interactively or in the background, as i just did that to tinker around and see if it'll work.

formatting
Source Link
Stefan
  • 26.7k
  • 3
  • 52
  • 88
Loading
Source Link
Loading