Skip to content

Instantly share code, notes, and snippets.

@railwaycat
Last active October 22, 2019 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save railwaycat/26f195feba1b4ce5df05e4bd01eb1d44 to your computer and use it in GitHub Desktop.
Save railwaycat/26f195feba1b4ce5df05e4bd01eb1d44 to your computer and use it in GitHub Desktop.
emacs mac port patch for org-9.2.6
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 7603f9688..d552d2095 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -555,7 +555,12 @@ use of this function is for the stuck project list."
(gui-get-selection value 'STRING)
(gui-get-selection value 'TEXT)))))
((and (eq window-system 'w32) (fboundp 'w32-get-clipboard-data))
- (w32-get-clipboard-data))))
+ (w32-get-clipboard-data))
+ ((and (eq window-system 'mac)
+ (fboundp 'gui-get-selection)) ;Silence byte-compiler.
+ (org-no-properties
+ (ignore-errors
+ (gui-get-selection 'CLIPBOARD 'NSStringPboardType))))))
;; `set-transient-map' is only in Emacs >= 24.4
(defalias 'org-set-transient-map
diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el
index 0577c3151..c5b7082bc 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -582,7 +582,7 @@ The location for a browser's bookmark should look like this:
;;; Core functions:
-(defun org-protocol-check-filename-for-protocol (fname restoffiles _client)
+(defun org-protocol-check-filename-for-protocol (fname restoffiles client)
"Check if `org-protocol-the-protocol' and a valid protocol are used in FNAME.
Sub-protocols are registered in `org-protocol-protocol-alist' and
`org-protocol-protocol-alist-default'. This is how the matching is done:
@@ -623,7 +623,10 @@ CLIENT is ignored."
(split (split-string fname proto))
(result (if greedy restoffiles (cadr split)))
(new-style (string= (match-string 1 fname) "?")))
- (when (plist-get (cdr prolist) :kill-client)
+ ;; Emacs Mac port directly handles `org-protocol'
+ ;; URLs without the help of external commands or
+ ;; apps. In this case, `client' is set to nil.
+ (when (and client (plist-get (cdr prolist) :kill-client))
(message "Greedy org-protocol handler. Killing client.")
(server-edit))
(when (fboundp func)
diff --git a/lisp/org.el b/lisp/org.el
index aa83e5b8b..0d3431c4c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18313,6 +18313,10 @@ for all fragments in the buffer."
'overlays msg 'forbuffer org-preview-latex-default-process))
(message (concat msg "done")))))))
+(declare-function mac-possibly-use-high-resolution-monitors-p
+ "term/mac-win" ())
+(declare-function mac-high-resolution-image-file-name
+ "term/mac-win" (filename &optional scale))
(defun org-format-latex
(prefix &optional beg end dir overlays msg forbuffer processing-type)
"Replace LaTeX fragments with links to an image.
@@ -18391,6 +18395,11 @@ Some of the options can be changed using the variable
(absprefix (expand-file-name prefix dir))
(linkfile (format "%s_%s.%s" prefix hash imagetype))
(movefile (format "%s_%s.%s" absprefix hash imagetype))
+ (move2xfile
+ (and (fboundp 'mac-high-resolution-image-file-name)
+ (not (string= imagetype "svg"))
+ (mac-possibly-use-high-resolution-monitors-p)
+ (mac-high-resolution-image-file-name movefile)))
(sep (and block-type "\n\n"))
(link (concat sep "[[file:" linkfile "]]" sep))
(options
@@ -18403,7 +18412,12 @@ Some of the options can be changed using the variable
(let ((todir (file-name-directory absprefix)))
(unless (file-directory-p todir)
(make-directory todir t))))
- (unless (file-exists-p movefile)
+ (unless (and (file-exists-p movefile)
+ (or (null move2xfile)
+ (file-exists-p move2xfile)))
+ (if move2xfile
+ (setq options
+ (plist-put options :to2xfile move2xfile)))
(org-create-formula-image
value movefile options forbuffer processing-type))
(if overlays
@@ -18585,6 +18599,7 @@ a HTML file."
"Black"))
(bg (or (plist-get options (if buffer :background :html-background))
"Transparent"))
+ (to2xfile (plist-get options :to2xfile))
(log-buf (get-buffer-create "*Org Preview LaTeX Output*"))
(resize-mini-windows nil)) ;Fix Emacs flicker when creating image.
(dolist (program programs)
@@ -18631,8 +18646,19 @@ a HTML file."
`((?F . ,(shell-quote-argument fg))
(?B . ,(shell-quote-argument bg))
(?D . ,(shell-quote-argument (format "%s" dpi)))
- (?S . ,(shell-quote-argument (format "%s" (/ dpi 140.0))))))))
+ (?S . ,(shell-quote-argument (format "%s" (/ dpi 140.0)))))))
+ (image-output-2x-file
+ (and
+ to2xfile
+ (org-compile-file
+ image-input-file image-converter image-output-type err-msg log-buf
+ `((?F . ,(shell-quote-argument fg))
+ (?B . ,(shell-quote-argument bg))
+ (?D . ,(shell-quote-argument (format "%s" (* dpi 2))))
+ (?S . ,(shell-quote-argument (format "%s" (/ dpi 140.0)))))))))
(copy-file image-output-file tofile 'replace)
+ (if to2xfile
+ (copy-file image-output-2x-file to2xfile 'replace))
(dolist (e post-clean)
(when (file-exists-p (concat texfilebase e))
(delete-file (concat texfilebase e))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment