Internal org mode links not exporting when buffer is narrowed - emacs

I need to periodically export to markdown various parts of a narrowed org buffer. When I run org-md-export-as-markdown (with org-export-with-broken-links set to t), the export works fine, except that all the links pointing to parts of the buffer outside the narrowed range fail to export.
For example, consider a buffer that contains the following text:
* Heading 1
** Heading 2
See [[*Heading 1][heading 1]].
The result of invoking org-md-export-as-markdown when the buffer is narrowed to Heading 2 is the following:
## Heading 2
See .
I tried using unique IDs instead, but the behavior is the same. Is there an org variable that controls how these links are exported, or a workaround to force Emacs to include these links? I understand that, since they point to a reference that doesn't exist in the exported file, the links would not work. However, I can easily automate the process of fixing these broken links, whereas if the links do not export at all, my only option is to recreate them manually.
My Org version is 9.4.4.

Related

Is there an Emacs read-only or view mode that allows inserting some text?

Here's the use case: I'm writing a novel in Emacs (in org-mode). One part of my writing/editing flow is to read over some large portion of what I've written, collecting notes/possible edits/etc as I go. The sort of thing you'd do, on paper, by printing it all out and then writing notes in the margin.
I want to prevent myself from, as I do this kind of review, actually doing any writing -- but that's surprisingly hard. Like, if the buffer is editable, I start to type a brief note about a fix, then find myself starting to restructure / fix a sentence, and next thing I know, I've spent five minute polishing
a single paragraph. This not only slows me down, it breaks my ability to imagine a reader's response.
I've tried just putting the buffer in view-mode, and that sort of works -- but then it's laborious to try to identify the places I want to go back and review/fix up.
My ideal would be, to have something in view-mode, which I genuinely can't edit, but which, as I move the cursor through it, I could hit some key combination, and it would allow me to enter a brief note in the minibuffer, which would then get inserted into the main buffer, at point, possibly inside brackets or a comment or some such.
Does anyone know of something like that? Or have any pointers to something similar which I could try to adapt?
You can easily set bookmarks at any locations. And bookmarks can contain annotations.
If you use library Bookmark+:
The annotations are in Org Mode by default, and they can even be separate files (by default they are part of the bookmarks themselves, so stored in your bookmarks file).
You can bookmark not just a position but also a region of text, whether a sentence, paragraph, page, or an arbitrary span of text.
You can automatically name bookmarks as you set them, if you don't care about the names.
Updated after OP's comment saying "I prefer to shove the comments/questions/notes directly into the text of the novel. Because I end up adding/deleting/moving text a ton, and I want the notes to move with the text":
Bookmarks move with the surrounding text. That is, they generally get relocated automatically, since the surrounding text is recorded as part of the bookmark, and when jumping to a bookmark that text is looked for.
Occasionally the context has changed so much that a bookmark can't be relocated automatically, and you are prompted to relocate it manually.
But yes, bookmarks are stored in a bookmark file, separately from the files they target. There are both advantages and disadvantages to this feature. Advantages include (1) removing clutter from the text (annotations, including notes about possible text changes are metadata), (2) immediate access to particular text locations from anywhere, (3) a separate, persistent record/history of work or thoughts on it, (4) you can have multiple, separate sets of bookmarks/annotations for the same target text.
One thing you might find handy, when using bookmarks especially for annotating a particular file: C-x p C-l switches to a bookmark file that has only bookmarks for the current file or buffer, creating such a file on the fly if none
exists. (This is available only with Bookmark+.)

emacs org-babel-tangle: ensure relative path of links in tangled comments

I'm using emacs 25.3.1 with Org mode version 9.1.9. I'm trying to ensure that the comments produced by the org-babel-tangle function and preceding the source block content in the tangled file contain the relative path to the original org file and not the absolute path. Although the documentation states that the org-babel-tangle-use-relative-file-links variable, which defaults to t, ensures this precise behaviour, I keep getting the absolute path in the links (e.g. # [[file:~/Projects/my_project/my_project.org::*setup.py][setup.py:1]]).
I tried setting this variable to nil but it didn't change anything. When manually changing the links with the relative path ( e.g. # [[file:../my_project.org::*setup.py][setup.py:1]]), invoking org-babel-detangle to integrate changes to the tangled file back to the original org file actually worked (with an additional interaction in the mini-buffer: No match - create this as a new heading? (y or n)).
Is there any way to get this relative path automatically from org-babel-tangle or is this a bug? This is a fairly important question if you think about projects with several contributors to a version controlled repository where
not everybody uses org-mode
obviously not everybody's working copy is located at the same absolute path on its own computer.

Emacs: How to associate different initialization configurations with different file formats?

What's the best way to associate file extensions with my own customizations? For example, when I open a .py file the frame would be bigger and split into 2 windows, but when a .tex file is opened the frame would be smaller with just one window. Should I split my .emacs and write all configurations associated with python in a .el file (key bindings, python shell = ipython, etc ...) and for latex in another .el file (load auctex, pdf mode = default, etc ...)? How would I "call" the files and make them work appropriately (if that'a possible and good solution)?
(First, +1 to #phils's comment. You will get better help if you are more specific about what you need/want.)
Depending on just what you need/want, see also variable (not option) file-name-handler-alist. You might not need it, but you might.
You can make use of it if you intend all or particular operations on the files to involve additional actions (such as those you describe). For any operations where you do not need special treatment, just provide the default behavior. For the others, provide the default behavior plus the extra behavior (in whichever order is appropriate).
See (elisp) Magic File Names for more information.

CEDET: storing tags manually

I'm using ECB with Cedet - and semantic search engine stores tags about the files I visit in its cache files.
I'm also using ECB's left-symboldef layout - which shows definition of the tag the cursor is on. In order to do that semantic opens the file where the tag was defined.
The problem is - semantic opens almost all of my python scripts all the time - since I have parser defined in all of them - when I parse command line arguments with argparse... So I'd rather stop semantic caching my files automatically, and do it manually with C-c , , on my libs only.
So my question is - how do I prevent semantic from storing cache? I should still be able to use the existing database (which I'll collect manually).
To prevent the automatic parsing of other files in idle time, you can set:
(setq semantic-idle-work-parse-neighboring-files-flag nil)
and if it is pulling them in via includes, you can do this:
(setq semantic-idle-work-update-headers-flag nil)
This is actually the default, and it gets set to true if you use one of the canned configuration options for regular or gaudy code helpers.
In order to not parse all the files, but still let ECB find tag definitions, you will probably need to use a GNU Global database. See semanticdb-enable-gnu-global-databases for more.

Emacs: Is there a way to generate a skeleton ChangeLog from diff?

I'd like to partly automate creation of GNU-style ChangeLog entries when working with source code in version control. The add-changelog-entry-other-window works with one file at a time and you have to visit the file to use it.
What I'd like to see instead is to have some command that would take an output of diff -u -p (or have integration with VC modes so it could process svn diff etc) and to create all the skeleton entries at once.
For example, if svn status shows
D file1.c
M file2.c
A file3.c
the command would create
2009-09-05 My Name <my.email>
* file1.c: Removed.
* file2.c: WRITE YOUR CHANGES HERE
* file3.c: New.
Better yet, if it could parse the changed files in some languages to an extent so it could offer:
* file2.c (new_function): New function.
(deleted_function): Removed.
(changed_function): WRITE YOUR CHANGES HERE
I have found this feature in Emacs manual, but I don't see how I could apply it here.
Any suggestions? Thanks.
EDIT: One answer suggested vc-update-change-log. Unfortunately it only supports CVS and it creates ChangeLog entries by querying the already-commited VC logs. Thus even if it supported svn and others, it would be impossible to commit the changes and the ChangeLog in the same commit.
EDIT2: Apparently add-changelog-entry-other-window (C-x 4 a) works not only from visited file but from diff hunk involving that file too. (Source) This is almost what I am looking for. This together with elisp loop to iterate through all hunks should solve it.
There is a function vc-update-change-log that automatically generates change log entries from the version control log entries.
diff-add-change-log-entries-other-window is documented to do exactly what you mentioned in EDIT2:
diff-add-change-log-entries-other-window is an interactive compiled
Lisp function in `diff-mode.el'.
(diff-add-change-log-entries-other-window)
Iterate through the current diff and create ChangeLog entries.
I.e. like `add-change-log-entry-other-window' but applied to all hunks.
Unfortunately, it doesn't work very well for, say, new files: it doesn't even include the filenames of such files in the skeletal changelog entry.
You might have better luck with gcc's mklog script, which you can get from http://gcc.gnu.org/viewcvs/gcc/trunk/contrib/mklog.
I don't know of a function that does this, but it should be easy to implement. Basically, you want to
get the changed files
for each file, call add-change-log
"Find change log file, and add an entry for today and an item for this file.
Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
name and email (stored in `add-log-full-name' and `add-log-mailing-address').
Second arg FILE-NAME is file name of the change log.
If nil, use the value of `change-log-default-name'.
Third arg OTHER-WINDOW non-nil means visit in other window.
Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
never append to an existing entry. Option `add-log-keep-changes-together'
otherwise affects whether a new entry is created.
Option `add-log-always-start-new-record' non-nil means always create a
new record, even when the last record was made on the same date and by
the same person.
The change log file can start with a copyright notice and a copying
permission notice. The first blank line indicates the end of these
notices.
Today's date is calculated according to `add-log-time-zone-rule' if
non-nil, otherwise in local time."
so the magic code is going to look something like
(apply 'make-magic-change-log-entry changed-files-list)
and make-magic-change-log-entry simply curries the add-change-log function so that the only argument is file-name — you set the other ones.
I've written a function to do something similar to what you were talking about. You can get the code at http://www.emacswiki.org/emacs/log-edit-fill