{"id":10623,"date":"2022-06-26T10:47:46","date_gmt":"2022-06-26T14:47:46","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=10623"},"modified":"2022-06-26T14:42:13","modified_gmt":"2022-06-26T18:42:13","slug":"capturing-the-current-file-location","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=10623","title":{"rendered":"Capturing the Current File Location"},"content":{"rendered":"<p>Marcin Borkowsi has a nice post on <a href=\"http:\/\/mbork.pl\/2022-06-20_Copying_the_current_location\">how to capture the current file\u2019s location and copy it to the system clipboard<\/a>. It\u2019s just what you need for sharing information about data in a file with a colleague. By file location he means the path to the file and the line number within that file.<\/p>\n<p>That doesn\u2019t seem too hard but there are some wrinkles. First of all you want the absolute line number within the file not just the number of the line visible in the buffer. That\u2019s pretty easy but the second problem is a bit trickier.<\/p>\n<p>Sometimes, just the name of the file is not enough. It may be that two files within a project have the same name but lives under a different subdirectory. Your first thought is probably to capture the full path to the file but that isn\u2019t optimal either. As Borkowski says, there\u2019s no point in showing the full path <i>on his machine<\/i>. What\u2019s needed is the path relative to the current project.<\/p>\n<p>That means the path relative to the current VC repository. It\u2019s pretty easy to get that with the <code>vc-root-dir<\/code> function. Borkowski has some code that captures the file path and line number and copies it to the system clipboard. It\u2019s simple and can be copied and used as is or modified to meet your particular needs.<\/p>\n<p>The post is definitely worth a read if only to discover how to deal with the various issues.<\/p>\n<p><b>UPDATE<\/b> <span class=\"timestamp-wrapper\"><span class=\"timestamp\">[2022-06-26 Sun 14:40]<\/span><\/span>: Added missing link to Borkowski\u2019s post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Marcin Borkowsi has a nice post on how to capture the current file\u2019s location and copy it to the system clipboard. It\u2019s just what you need for sharing information about data in a file with a colleague. By file location &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=10623\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18],"class_list":["post-10623","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10623"}],"version-history":[{"count":2,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10623\/revisions"}],"predecessor-version":[{"id":10625,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10623\/revisions\/10625"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}