{"action":"created","comment":{"url":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/comments/42288965","id":42288965,"diff_hunk":"@@ -114,6 +128,57 @@ for files that it cannot handle.\"\n ;; Functions\n ;;\n \n+(defun irony-cdb--choose-closest-path (file paths)\n+  \"Find the \\\"best\\\" path in PATHS matching FILE\n+\n+If any paths in PATHS is belongs to the same directory\n+or a subdirectory of file, we disregard other candidates.\n+\n+For remaining candidates, \\\"nearest\\\" is measured as abs. difference\n+in path depth.\n+- We prefer deeper paths at level +N to those at level -N.\n+- If multiple paths are equally good, we return the last one.\n+\n+Returns nil if paths isn't a list of at least one element.\n+\"\n+  (when (listp paths)\n+    (let ((paths (or\n+                  ;; if we find a cdb in cwd or below, don't consider other candidates\n+                  (cl-remove-if-not (lambda (x) (string-prefix-p (file-name-directory file) x)) paths)\n+                  paths)))\n+      (cl-loop for path in paths\n+         with best-depth-delta = 999999 ; start at +inf\n+         with best-path = nil ; we keep the best so far here\n+         ;; all candidates have their depth compared to that of target file\n+         with file-depth = (length (split-string file \"/\")) ;","path":"irony-cdb.el","position":47,"original_position":47,"commit_id":"2f86314d7c92545e438fcfc0a18031255e25b146","original_commit_id":"2f86314d7c92545e438fcfc0a18031255e25b146","user":{"login":"MikeSanMichel2","id":14960200,"avatar_url":"https://avatars.githubusercontent.com/u/14960200?v=3","gravatar_id":"","url":"https://api.github.com/users/MikeSanMichel2","html_url":"https://github.com/MikeSanMichel2","followers_url":"https://api.github.com/users/MikeSanMichel2/followers","following_url":"https://api.github.com/users/MikeSanMichel2/following{/other_user}","gists_url":"https://api.github.com/users/MikeSanMichel2/gists{/gist_id}","starred_url":"https://api.github.com/users/MikeSanMichel2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MikeSanMichel2/subscriptions","organizations_url":"https://api.github.com/users/MikeSanMichel2/orgs","repos_url":"https://api.github.com/users/MikeSanMichel2/repos","events_url":"https://api.github.com/users/MikeSanMichel2/events{/privacy}","received_events_url":"https://api.github.com/users/MikeSanMichel2/received_events","type":"User","site_admin":false},"body":"`buffer-file-name` isn't strictly one of the functions in that section, so I added 2c53d40 to be safe.","created_at":"2015-10-16T20:52:51Z","updated_at":"2015-10-16T20:52:51Z","html_url":"https://github.com/Sarcasm/irony-mode/pull/237#discussion_r42288965","pull_request_url":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237","_links":{"self":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/comments/42288965"},"html":{"href":"https://github.com/Sarcasm/irony-mode/pull/237#discussion_r42288965"},"pull_request":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237"}}},"pull_request":{"url":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237","id":47215207,"html_url":"https://github.com/Sarcasm/irony-mode/pull/237","diff_url":"https://github.com/Sarcasm/irony-mode/pull/237.diff","patch_url":"https://github.com/Sarcasm/irony-mode/pull/237.patch","issue_url":"https://api.github.com/repos/Sarcasm/irony-mode/issues/237","number":237,"state":"closed","locked":false,"title":"Useful additions to irony-cdb-json","user":{"login":"MikeSanMichel2","id":14960200,"avatar_url":"https://avatars.githubusercontent.com/u/14960200?v=3","gravatar_id":"","url":"https://api.github.com/users/MikeSanMichel2","html_url":"https://github.com/MikeSanMichel2","followers_url":"https://api.github.com/users/MikeSanMichel2/followers","following_url":"https://api.github.com/users/MikeSanMichel2/following{/other_user}","gists_url":"https://api.github.com/users/MikeSanMichel2/gists{/gist_id}","starred_url":"https://api.github.com/users/MikeSanMichel2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MikeSanMichel2/subscriptions","organizations_url":"https://api.github.com/users/MikeSanMichel2/orgs","repos_url":"https://api.github.com/users/MikeSanMichel2/repos","events_url":"https://api.github.com/users/MikeSanMichel2/events{/privacy}","received_events_url":"https://api.github.com/users/MikeSanMichel2/received_events","type":"User","site_admin":false},"body":"closes #234, #236 maybe some issues linked there as well. \r\n\r\nFirst, now looks recursively for parents for both \".json\" and \"build/.json\". (#234)\r\n\r\nSecond, #236. One confusing bit is that calling `irony-cdb-json-add-compile-commands-path`\r\ndoesn't actually finish by loading the database you added. That might be \"Cleaner\", but\r\nits inconvenient and under-documented. Commit 2 fixes that.\r\n\r\nThird, still #236, I was led astray by `add-compile-commands-path` asking for both\r\nproject root and cdb path and ended up choosing the build directory, then the file within it.\r\nI may not have been paying enough attention, but the issues suggest I may not be\r\nthe only one. So, commit 3 adds an alternative which takes only a cdb path,\r\nloads it, and uses the source file paths in it to find the project root as the deepest\r\ndir parenting everything in the cdb.\r\nI would have just replaced `add-compile-commands-path` entirely, but that's public\r\nand the new function takes one argument less. If you like the idea and don't mind\r\nbreaking the API, go for it.\r\n\r\nPlease review/test, I only wrote it, I haven't actually tested it (much) :)\r\n\r\nIf you merge 1m my problem is basically solved. 2 I think is reasonable. 3 was just\r\nfrustration.","created_at":"2015-10-08T22:34:47Z","updated_at":"2015-10-16T20:52:51Z","closed_at":"2015-10-16T20:49:35Z","merged_at":null,"merge_commit_sha":"131aa9b773e684bef99a46fa04307ec31fef00c1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237/commits","review_comments_url":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237/comments","review_comment_url":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Sarcasm/irony-mode/issues/237/comments","statuses_url":"https://api.github.com/repos/Sarcasm/irony-mode/statuses/2f86314d7c92545e438fcfc0a18031255e25b146","head":{"label":"MikeSanMichel2:cdb_json_fixes1","ref":"cdb_json_fixes1","sha":"2f86314d7c92545e438fcfc0a18031255e25b146","user":{"login":"MikeSanMichel2","id":14960200,"avatar_url":"https://avatars.githubusercontent.com/u/14960200?v=3","gravatar_id":"","url":"https://api.github.com/users/MikeSanMichel2","html_url":"https://github.com/MikeSanMichel2","followers_url":"https://api.github.com/users/MikeSanMichel2/followers","following_url":"https://api.github.com/users/MikeSanMichel2/following{/other_user}","gists_url":"https://api.github.com/users/MikeSanMichel2/gists{/gist_id}","starred_url":"https://api.github.com/users/MikeSanMichel2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MikeSanMichel2/subscriptions","organizations_url":"https://api.github.com/users/MikeSanMichel2/orgs","repos_url":"https://api.github.com/users/MikeSanMichel2/repos","events_url":"https://api.github.com/users/MikeSanMichel2/events{/privacy}","received_events_url":"https://api.github.com/users/MikeSanMichel2/received_events","type":"User","site_admin":false},"repo":{"id":43919011,"name":"irony-mode","full_name":"MikeSanMichel2/irony-mode","owner":{"login":"MikeSanMichel2","id":14960200,"avatar_url":"https://avatars.githubusercontent.com/u/14960200?v=3","gravatar_id":"","url":"https://api.github.com/users/MikeSanMichel2","html_url":"https://github.com/MikeSanMichel2","followers_url":"https://api.github.com/users/MikeSanMichel2/followers","following_url":"https://api.github.com/users/MikeSanMichel2/following{/other_user}","gists_url":"https://api.github.com/users/MikeSanMichel2/gists{/gist_id}","starred_url":"https://api.github.com/users/MikeSanMichel2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MikeSanMichel2/subscriptions","organizations_url":"https://api.github.com/users/MikeSanMichel2/orgs","repos_url":"https://api.github.com/users/MikeSanMichel2/repos","events_url":"https://api.github.com/users/MikeSanMichel2/events{/privacy}","received_events_url":"https://api.github.com/users/MikeSanMichel2/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MikeSanMichel2/irony-mode","description":"A C/C++ minor mode for Emacs powered by libclang","fork":true,"url":"https://api.github.com/repos/MikeSanMichel2/irony-mode","forks_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/forks","keys_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/teams","hooks_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/hooks","issue_events_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/issues/events{/number}","events_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/events","assignees_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/assignees{/user}","branches_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/branches{/branch}","tags_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/tags","blobs_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/git/refs{/sha}","trees_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/statuses/{sha}","languages_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/languages","stargazers_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/stargazers","contributors_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/contributors","subscribers_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/subscribers","subscription_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/subscription","commits_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/commits{/sha}","git_commits_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/git/commits{/sha}","comments_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/comments{/number}","issue_comment_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/issues/comments{/number}","contents_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/contents/{+path}","compare_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/merges","archive_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/downloads","issues_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/issues{/number}","pulls_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/pulls{/number}","milestones_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/milestones{/number}","notifications_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/labels{/name}","releases_url":"https://api.github.com/repos/MikeSanMichel2/irony-mode/releases{/id}","created_at":"2015-10-08T22:11:33Z","updated_at":"2015-10-08T22:11:34Z","pushed_at":"2015-10-16T20:52:04Z","git_url":"git://github.com/MikeSanMichel2/irony-mode.git","ssh_url":"git@github.com:MikeSanMichel2/irony-mode.git","clone_url":"https://github.com/MikeSanMichel2/irony-mode.git","svn_url":"https://github.com/MikeSanMichel2/irony-mode","homepage":"","size":1056,"stargazers_count":0,"watchers_count":0,"language":"Emacs Lisp","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Sarcasm:master","ref":"master","sha":"3d7fe7cd43a070a57527d7a8fd1b98bc086848b8","user":{"login":"Sarcasm","id":424046,"avatar_url":"https://avatars.githubusercontent.com/u/424046?v=3","gravatar_id":"","url":"https://api.github.com/users/Sarcasm","html_url":"https://github.com/Sarcasm","followers_url":"https://api.github.com/users/Sarcasm/followers","following_url":"https://api.github.com/users/Sarcasm/following{/other_user}","gists_url":"https://api.github.com/users/Sarcasm/gists{/gist_id}","starred_url":"https://api.github.com/users/Sarcasm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sarcasm/subscriptions","organizations_url":"https://api.github.com/users/Sarcasm/orgs","repos_url":"https://api.github.com/users/Sarcasm/repos","events_url":"https://api.github.com/users/Sarcasm/events{/privacy}","received_events_url":"https://api.github.com/users/Sarcasm/received_events","type":"User","site_admin":false},"repo":{"id":2564641,"name":"irony-mode","full_name":"Sarcasm/irony-mode","owner":{"login":"Sarcasm","id":424046,"avatar_url":"https://avatars.githubusercontent.com/u/424046?v=3","gravatar_id":"","url":"https://api.github.com/users/Sarcasm","html_url":"https://github.com/Sarcasm","followers_url":"https://api.github.com/users/Sarcasm/followers","following_url":"https://api.github.com/users/Sarcasm/following{/other_user}","gists_url":"https://api.github.com/users/Sarcasm/gists{/gist_id}","starred_url":"https://api.github.com/users/Sarcasm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sarcasm/subscriptions","organizations_url":"https://api.github.com/users/Sarcasm/orgs","repos_url":"https://api.github.com/users/Sarcasm/repos","events_url":"https://api.github.com/users/Sarcasm/events{/privacy}","received_events_url":"https://api.github.com/users/Sarcasm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Sarcasm/irony-mode","description":"A C/C++ minor mode for Emacs powered by libclang","fork":false,"url":"https://api.github.com/repos/Sarcasm/irony-mode","forks_url":"https://api.github.com/repos/Sarcasm/irony-mode/forks","keys_url":"https://api.github.com/repos/Sarcasm/irony-mode/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Sarcasm/irony-mode/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Sarcasm/irony-mode/teams","hooks_url":"https://api.github.com/repos/Sarcasm/irony-mode/hooks","issue_events_url":"https://api.github.com/repos/Sarcasm/irony-mode/issues/events{/number}","events_url":"https://api.github.com/repos/Sarcasm/irony-mode/events","assignees_url":"https://api.github.com/repos/Sarcasm/irony-mode/assignees{/user}","branches_url":"https://api.github.com/repos/Sarcasm/irony-mode/branches{/branch}","tags_url":"https://api.github.com/repos/Sarcasm/irony-mode/tags","blobs_url":"https://api.github.com/repos/Sarcasm/irony-mode/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Sarcasm/irony-mode/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Sarcasm/irony-mode/git/refs{/sha}","trees_url":"https://api.github.com/repos/Sarcasm/irony-mode/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Sarcasm/irony-mode/statuses/{sha}","languages_url":"https://api.github.com/repos/Sarcasm/irony-mode/languages","stargazers_url":"https://api.github.com/repos/Sarcasm/irony-mode/stargazers","contributors_url":"https://api.github.com/repos/Sarcasm/irony-mode/contributors","subscribers_url":"https://api.github.com/repos/Sarcasm/irony-mode/subscribers","subscription_url":"https://api.github.com/repos/Sarcasm/irony-mode/subscription","commits_url":"https://api.github.com/repos/Sarcasm/irony-mode/commits{/sha}","git_commits_url":"https://api.github.com/repos/Sarcasm/irony-mode/git/commits{/sha}","comments_url":"https://api.github.com/repos/Sarcasm/irony-mode/comments{/number}","issue_comment_url":"https://api.github.com/repos/Sarcasm/irony-mode/issues/comments{/number}","contents_url":"https://api.github.com/repos/Sarcasm/irony-mode/contents/{+path}","compare_url":"https://api.github.com/repos/Sarcasm/irony-mode/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Sarcasm/irony-mode/merges","archive_url":"https://api.github.com/repos/Sarcasm/irony-mode/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Sarcasm/irony-mode/downloads","issues_url":"https://api.github.com/repos/Sarcasm/irony-mode/issues{/number}","pulls_url":"https://api.github.com/repos/Sarcasm/irony-mode/pulls{/number}","milestones_url":"https://api.github.com/repos/Sarcasm/irony-mode/milestones{/number}","notifications_url":"https://api.github.com/repos/Sarcasm/irony-mode/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Sarcasm/irony-mode/labels{/name}","releases_url":"https://api.github.com/repos/Sarcasm/irony-mode/releases{/id}","created_at":"2011-10-12T19:07:26Z","updated_at":"2015-10-16T03:31:36Z","pushed_at":"2015-10-16T20:47:43Z","git_url":"git://github.com/Sarcasm/irony-mode.git","ssh_url":"git@github.com:Sarcasm/irony-mode.git","clone_url":"https://github.com/Sarcasm/irony-mode.git","svn_url":"https://github.com/Sarcasm/irony-mode","homepage":"","size":2155,"stargazers_count":347,"watchers_count":347,"language":"Emacs Lisp","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":54,"mirror_url":null,"open_issues_count":47,"forks":54,"open_issues":47,"watchers":347,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237"},"html":{"href":"https://github.com/Sarcasm/irony-mode/pull/237"},"issue":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/issues/237"},"comments":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/issues/237/comments"},"review_comments":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237/comments"},"review_comment":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/pulls/237/commits"},"statuses":{"href":"https://api.github.com/repos/Sarcasm/irony-mode/statuses/2f86314d7c92545e438fcfc0a18031255e25b146"}}}}