Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let Org-mode open a link like [[file://file.org]] in current window instead of default in other window?

Tags:

emacs

org-mode

I hope to use [C-c C-o] to open a link like [[file://filename.org|filename]] in current window, instead of the default in other window.

How to change this Org-mode default behavior ?

Seems default [C-u C-c C-o] is force open link in other window.

And there is a similar question at here: How do I keep Emacs org-mode from splitting windows?

like image 360
stardiviner Avatar asked Jul 11 '13 10:07

stardiviner


People also ask

How do I set up org mode?

To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores. MY PROJECT is the title of the document, this can be anything. This will enable Org mode for this document, no matter what the file-ending is.

What is ORG mode used for?

Org Mode (also: org-mode; /ˈɔːrɡ moʊd/) is a document editing, formatting, and organizing mode, designed for notes, planning, and authoring within the free software text editor Emacs.

How do I know what version of org mode I have?

It maybe under status 'built-in' or 'installed', if you click on org then it will tell you the version.


2 Answers

You need to change the value of org-link-frame-setup. Default value contains the cons (file . find-file-other-window). You may replace it by (file . find-file).

like image 152
juanleon Avatar answered Sep 18 '22 22:09

juanleon


Here is the solution I wrote, inspired by the answer of @juanleon. It maps C-c C-o to open the link in the current window, but leaves the default behaviour for C-u C-c C-o (open in other window). It does so without breaking the universal argument function (which happens for me when I naively remap C-u C-c C-o).

(defun org-force-open-current-window ()
  (interactive)
  (let ((org-link-frame-setup (quote
                               ((vm . vm-visit-folder)
                                (vm-imap . vm-visit-imap-folder)
                                (gnus . gnus)
                                (file . find-file)
                                (wl . wl)))
                              ))
    (org-open-at-point)))
;; Depending on universal argument try opening link
(defun org-open-maybe (&optional arg)
  (interactive "P")
  (if arg
      (org-open-at-point)
    (org-force-open-current-window)
    )
  )
;; Redefine file opening without clobbering universal argumnet
(define-key org-mode-map "\C-c\C-o" 'org-open-maybe)
like image 22
wuzwm Avatar answered Sep 18 '22 22:09

wuzwm