girzel / ebdb

An EIEIO port of BBDB, Emacs' contact-management package
67 stars 12 forks source link

Adding images results in error for propertize #100

Closed DerBeutlin closed 2 years ago

DerBeutlin commented 2 years ago

Hi I tried adding an image to a contact using

ebdb-insert-field -> image - find image file ? (y) -> choose file.

However I get then the error (wrong-number-of-arguments propertize 2) and I keep getting the error whenever I do an ebdb action afterwards unless I restart emacs without saving the ebdb changes.

The whole traceback is

  propertize(" " (display (image :type jpeg :file "PATH_TO_IMAGE" :scale 1.0021276595744681 :transform-smoothing t) rear-nonsticky (display) keymap (keymap (111 . image-save) (114 . image-rotate) (C-mouse-4 . image-mouse-increase-size) (C-wheel-up . image-mouse-increase-size) (C-mouse-5 . image-mouse-decrease-size) (C-wheel-down . image-mouse-decrease-size) (43 . image-increase-size) (45 . image-decrease-size))))
  #f(compiled-function (fmt field style record) #<bytecode -0x8654490e8c9493a>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (fmt field style record) #<bytecode -0x8654490e8c9493a>) (#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>))
  #f(compiled-function (&rest cnm-args) #<bytecode -0x7dd7a7acce1c021>)()
  #f(compiled-function (cl--cnm fmt field style record) "Put the 'ebdb-field text property on FIELD.  The value of the\nproperty is the field instance itself." #<bytecode 0x1c7a5db443cbe014>)(#f(compiled-function (&rest cnm-args) #<bytecode -0x7dd7a7acce1c021>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (cl--cnm fmt field style record) "Put the 'ebdb-field text property on FIELD.  The value of the\nproperty is the field instance itself." #<bytecode 0x1c7a5db443cbe014>) #f(compiled-function (&rest cnm-args) #<bytecode -0x7dd7a7acce1c021>) (#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>))
  #f(compiled-function (&rest args) #<bytecode -0x2af798279d2aabd>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (&rest args) #<bytecode -0x2af798279d2aabd>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> (#<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>))
  #f(compiled-function (arg &rest args) #<bytecode -0x1ec14934cdc79624>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (arg &rest args) #<bytecode -0x1ec14934cdc79624>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> (normal #<ebdb-record-person XXX_NAME_XXX>))
  #f(compiled-function (arg0 arg &rest args) #<bytecode -0x3a8c612369b63e5>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (arg0 arg &rest args) #<bytecode -0x3a8c612369b63e5>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  #f(compiled-function (arg0 arg1 arg &rest args) #<bytecode 0xa9e207ffe0659a>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (arg0 arg1 arg &rest args) #<bytecode 0xa9e207ffe0659a>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX> nil)
  ebdb-fmt-field(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-field-image ebdb-field-image-77326b8> normal #<ebdb-record-person XXX_NAME_XXX>)
  #f(compiled-function (f) #<bytecode -0x4038192d004fa89>)(#<ebdb-field-image ebdb-field-image-77326b8>)
  mapconcat(#f(compiled-function (f) #<bytecode -0x4038192d004fa89>) (#<ebdb-field-image ebdb-field-image-77326b8>) " ")
  #f(compiled-function (arg0) #<bytecode 0x13897c832ed2f3c4>)(((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)))
  mapconcat(#f(compiled-function (arg0) #<bytecode 0x13897c832ed2f3c4>) (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal))) " ")
  #f(compiled-function (fmt record &optional header-fields) #<bytecode 0x25b716bc85d9fb8>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal))))
  apply(#f(compiled-function (fmt record &optional header-fields) #<bytecode 0x25b716bc85d9fb8>) (#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal)))))
  #f(compiled-function (&rest cnm-args) #<bytecode 0x1794d65f69d0840f>)()
  #f(compiled-function (cl--cnm fmt record &optional header-fields) #<bytecode -0xfde77235377c9f6>)(#f(compiled-function (&rest cnm-args) #<bytecode 0x1794d65f69d0840f>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal))))
  apply(#f(compiled-function (cl--cnm fmt record &optional header-fields) #<bytecode -0xfde77235377c9f6>) #f(compiled-function (&rest cnm-args) #<bytecode 0x1794d65f69d0840f>) (#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal)))))
  #f(compiled-function (&rest args) #<bytecode 0x12ddec944ea4b7ad>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal))))
  apply(#f(compiled-function (&rest args) #<bytecode 0x12ddec944ea4b7ad>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> (#<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal)))))
  #f(compiled-function (arg &rest args) #<bytecode 0x1d28e46f4764c19c>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal))))
  apply(#f(compiled-function (arg &rest args) #<bytecode 0x1d28e46f4764c19c>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal))))
  ebdb-fmt-record-header(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> (((class . ebdb-field-image) (inst #<ebdb-field-image ebdb-field-image-77326b8>) (style . normal)) ((class . ebdb-field-role) (inst #<ebdb-field-role ebdb-field-role-7739944>) (style . normal))))
  #f(compiled-function (fmt record) #<bytecode -0x594cd116119c12a>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (fmt record) #<bytecode -0x594cd116119c12a>) (#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>))
  #f(compiled-function (&rest cnm-args) #<bytecode -0xbc1a73f8f736a17>)()
  #f(compiled-function (cl--cnm fmt record) #<bytecode -0x18261ad865234212>)(#f(compiled-function (&rest cnm-args) #<bytecode -0xbc1a73f8f736a17>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (cl--cnm fmt record) #<bytecode -0x18261ad865234212>) #f(compiled-function (&rest cnm-args) #<bytecode -0xbc1a73f8f736a17>) (#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>))
  #f(compiled-function (&rest args) #<bytecode -0x4a2f8999b22d7a>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (&rest args) #<bytecode -0x4a2f8999b22d7a>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>)
  #f(compiled-function (arg &rest args) #<bytecode -0x1a3120e099faba24>)(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>)
  apply(#f(compiled-function (arg &rest args) #<bytecode -0x1a3120e099faba24>) #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX> nil)
  ebdb-fmt-record(#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<ebdb-record-person XXX_NAME_XXX>)
  #f(compiled-function (record fmt full-record) #<bytecode 0x46ecc7261ddf74e>)(#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  apply(#f(compiled-function (record fmt full-record) #<bytecode 0x46ecc7261ddf74e>) #<ebdb-record-person XXX_NAME_XXX> (#<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil)))
  #f(compiled-function (arg &rest args) #<bytecode -0x1aa59d8dffdf67d0>)(#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  apply(#f(compiled-function (arg &rest args) #<bytecode -0x1aa59d8dffdf67d0>) #<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  ebdb-redisplay-record(#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  #f(compiled-function (record action full-record) #<bytecode 0x5460c2209c9fe6b>)(#<ebdb-record-person XXX_NAME_XXX> reformat (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  apply(#f(compiled-function (record action full-record) #<bytecode 0x5460c2209c9fe6b>) #<ebdb-record-person XXX_NAME_XXX> (reformat (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil)))
  #f(compiled-function (arg &rest args) #<bytecode -0x1aa5961c08f967d0>)(#<ebdb-record-person XXX_NAME_XXX> reformat (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  apply(#f(compiled-function (arg &rest args) #<bytecode -0x1aa5961c08f967d0>) #<ebdb-record-person XXX_NAME_XXX> reformat (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  ebdb-redisplay-record(#<ebdb-record-person XXX_NAME_XXX> reformat (#<ebdb-record-person XXX_NAME_XXX> #<ebdb-formatter-ebdb-multiline ebdb-formatter-ebdb-multiline-8b3f2b4> #<marker at 259 in *EBDB*> nil))
  ebdb-redisplay-records(#<ebdb-record-person XXX_NAME_XXX> reformat nil)
  ebdb-insert-field((#<ebdb-record-person XXX_NAME_XXX>))
  funcall-interactively(ebdb-insert-field (#<ebdb-record-person XXX_NAME_XXX>))
  command-execute(ebdb-insert-field record)
  counsel-M-x-action("ebdb-insert-field")

What am I doing wrong?

girzel commented 2 years ago

You're doing nothing wrong, apart from attempting to use code no one has used before! Would you eval the below and see if it fixes the error?

I imagine there will be all sorts of weirdness with displaying the actual image, but let's at least get the bug out of there first.

(cl-defmethod ebdb-fmt-field ((_fmt ebdb-formatter-ebdb)
                  (field ebdb-field-image)
                  _style
                  (record ebdb-record))
  (if (display-images-p)
      (progn
    (require 'image)
    (apply
     #'propertize
     " "
     ;; Cribbed from `insert-image'.
     (list 'display (ebdb-field-image-get field record)
               'rear-nonsticky '(display)
               'keymap image-map)))
    "<img>"))
DerBeutlin commented 2 years ago

Yes that made it work! The display works fine although the scaling is not optimal. Thanks!

girzel commented 2 years ago

Good to hear. I wonder what we can do about the scaling. Do you just mean that the image is too large/small? Or that the actual aspect ratio is off?

DerBeutlin commented 2 years ago

No the aspect ratio is fine, it's just a bit large :)

girzel commented 2 years ago

Okay good. I guess I'll give image fields a "scale" parameter, which takes either an integer for width in pixels, or a float for percentage of window width. Then just give it a reasonable default. I don't know much about image display in Emacs, so this might take me a bit.

girzel commented 2 years ago

Okay, this fix is in, along with a new option ebdb-image-additional-plist that you can use to control image sizing. I'm going to close this for now, but if anything doesn't work right please feel free to re-open or start a new issue. Thanks.